Compare commits
	
		
			No commits in common. "0320197147ace1a60add3a82a912657af9aab162" and "8f0e9759c42bc46a2c0c0256c99e1e5487cb2e00" have entirely different histories.
		
	
	
		
			0320197147
			...
			8f0e9759c4
		
	
		
| @ -10,7 +10,6 @@ import ( | ||||
| 	"git.fjla.uk/owlboard/timetable-mgr/corpus" | ||||
| 	"git.fjla.uk/owlboard/timetable-mgr/helpers" | ||||
| 	"git.fjla.uk/owlboard/timetable-mgr/log" | ||||
| 	"git.fjla.uk/owlboard/timetable-mgr/pis" | ||||
| 	"git.fjla.uk/owlboard/timetable-mgr/stations" | ||||
| 	"go.uber.org/zap" | ||||
| ) | ||||
| @ -43,7 +42,6 @@ func runTicker(cfg *helpers.Configuration, stop <-chan struct{}) { | ||||
| 			go cif.CheckCif(cfg) | ||||
| 			go corpus.CheckCorpus(cfg) | ||||
| 			go stations.Check() | ||||
| 			go pis.Check() | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -5,7 +5,7 @@ import ( | ||||
| ) | ||||
| 
 | ||||
| // Version Constants | ||||
| const versionNum string = "2024.10.0" | ||||
| const versionNum string = "2024.06.0" | ||||
| const versionSuffix string = "" | ||||
| const Version string = versionNum + versionSuffix | ||||
| 
 | ||||
|  | ||||
| @ -61,7 +61,7 @@ func Check() { | ||||
| 
 | ||||
| 	log.Info("PIS Data being updated") | ||||
| 	err = runUpdate(apiResp.TarballUrl) | ||||
| 	if err != nil { | ||||
| 	if err == nil { | ||||
| 		log.Error("Error updating PIS Data", zap.Error(err)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
							
								
								
									
										31
									
								
								pis/data.go
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								pis/data.go
									
									
									
									
									
								
							| @ -2,23 +2,19 @@ package pis | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	"gopkg.in/yaml.v3" | ||||
| ) | ||||
| 
 | ||||
| // Process the YAML data to a struct | ||||
| func processYaml(yamlStr string) (*[]PisData, error) { | ||||
| 	var pis []PisData | ||||
| func processYaml(yamlStr string) (*PisData, error) { | ||||
| 	var pis PisData | ||||
| 
 | ||||
| 	// Unmarshal the YAML data into a slice of PisData | ||||
| 	err := yaml.Unmarshal([]byte(yamlStr), &pis) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("failed to unmarshal YAML: %v", err) | ||||
| 	} | ||||
| 
 | ||||
| 	// Perform deduplication on the entire pis slice | ||||
| 	err = deduplicateCodes(&pis) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @ -28,25 +24,6 @@ func processYaml(yamlStr string) (*[]PisData, error) { | ||||
| } | ||||
| 
 | ||||
| // Deduplicate data in place and return error if failed | ||||
| func deduplicateCodes(pis *[]PisData) error { | ||||
| 	uniqueStops := make(map[string]bool) | ||||
| 	var dedupedPis []PisData | ||||
| 
 | ||||
| 	for _, data := range *pis { | ||||
| 		stopsKey := stopsToString(data.Stops) | ||||
| 
 | ||||
| 		// If stopsKey does not exist, add to map | ||||
| 		if _, exists := uniqueStops[stopsKey]; !exists { | ||||
| 			uniqueStops[stopsKey] = true | ||||
| 			dedupedPis = append(dedupedPis, data) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	*pis = dedupedPis | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func stopsToString(stops []string) string { | ||||
| 	sort.Strings(stops) | ||||
| 	return strings.Join(stops, ",") | ||||
| func deduplicateCodes(pis *PisData) error { | ||||
| 	return fmt.Errorf("deduplication logic not present, unable to update") | ||||
| } | ||||
|  | ||||
| @ -42,13 +42,7 @@ func runUpdate(tarballUrl string) error { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	pisSlice, err := processYaml(pisData) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	fmt.Println(&pisSlice) | ||||
| 	// Replace db contents with new pis data | ||||
| 	// Replace database collection with new data | ||||
| 	// Ensure indeces are present | ||||
| 
 | ||||
| 	// Cleanup files | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user