From ffdb18d0287fde892c4137bfd0bf2af28786c218 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 17 Jul 2018 09:29:31 -0700 Subject: [PATCH] bug fix: allow location names as numbers --- server/ai/src/learn.py | 16 +++++++++++----- server/main/src/api/calibration.go | 1 + server/main/src/database/db.go | 6 ++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/server/ai/src/learn.py b/server/ai/src/learn.py index 7c8a4c7e6..7487a334e 100755 --- a/server/ai/src/learn.py +++ b/server/ai/src/learn.py @@ -191,21 +191,27 @@ def learn(self, fname): with open(fname, 'r') as csvfile: reader = csv.reader(csvfile, delimiter=',') for i, row in enumerate(reader): + self.logger.debug(row) if i == 0: self.header = row else: for j, val in enumerate(row): + if j == 0: + # this is a name of the location + if val not in self.naming['from']: + self.naming['from'][val] = naming_num + self.naming['to'][naming_num] = val + naming_num += 1 + row[j] = self.naming['from'][val] + continue if val == '': row[j] = 0 continue try: row[j] = float(val) except: - if val not in self.naming['from']: - self.naming['from'][val] = naming_num - self.naming['to'][naming_num] = val - naming_num += 1 - row[j] = self.naming['from'][val] + self.logger.error( + "problem parsing value " + str(val)) rows.append(row) # first column in row is the classification, Y diff --git a/server/main/src/api/calibration.go b/server/main/src/api/calibration.go index 4bd8884c7..41c6922d7 100644 --- a/server/main/src/api/calibration.go +++ b/server/main/src/api/calibration.go @@ -234,6 +234,7 @@ func findBestAlgorithm(datas []models.SensorData) (algorithmEfficacy map[string] } if len(aidata.LocationNames) == 0 { err = errors.New("no location names") + logger.Log.Error(err) return } guessedLocation := aidata.LocationNames[prediction.Locations[0]] diff --git a/server/main/src/database/db.go b/server/main/src/database/db.go index 1b4ce2c6f..518ec9e13 100755 --- a/server/main/src/database/db.go +++ b/server/main/src/database/db.go @@ -191,6 +191,12 @@ func (d *Database) Dump() (dumped string, err error) { // AddPrediction will insert or update a prediction in the database func (d *Database) AddPrediction(timestamp int64, aidata []models.LocationPrediction) (err error) { + // make sure we have a prediction + if len(aidata) == 0 { + err = errors.New("no predictions to add") + return + } + // truncate to two digits for i := range aidata { aidata[i].Probability = float64(int64(float64(aidata[i].Probability)*100)) / 100