Skip to content

Commit

Permalink
bug fix: allow location names as numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Jul 17, 2018
1 parent a4473b8 commit ffdb18d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
16 changes: 11 additions & 5 deletions server/ai/src/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions server/main/src/api/calibration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
6 changes: 6 additions & 0 deletions server/main/src/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffdb18d

Please sign in to comment.