def save(line): if len(line.points) <= 2: raise Exception("length of input or reference is below 3. Scale-Matching lines of size <3 is not possible.") # only use dbline if to be committed by session/stored or retrieved from db tobesaved = DBLine.from_numpy_array(line.to_numpy_array()) tobesaved.store() log.info("created line id %d" % (tobesaved.id)) return tobesaved.id
def get(line): dbline = DBLine.get(line.id) if type(dbline) != NoneType: found = ABCLine.from_numpy_array(dbline.to_numpy_array()) found.id = dbline.id log.info("retrieved line id %d" % (found.id)) return found else: log.error("line id %d does not exist!" % (line.id)) echo = ABCLine() echo.id = 0 return echo
def delete(line): dbline = DBLine.get(line.id) if type(dbline) != NoneType: # or dbline.view(matchline.ABCLine) ? echo = ABCLine.from_numpy_array(dbline.to_numpy_array()) echo.id = dbline.id dbline.remove() log.info("deleted line id %d" % (line.id)) return echo else: log.error("line id %d does not exist!" % (line.id)) echo = ABCLine() echo.id = 0 return echo
def populate_lines(echo, lines): varray = ABCSymbol() for count, record_id in enumerate(lines): # bug workaround: macos ppc #if count < 60: line = DBLine.get(record_id) #strangely this is necessary to populate (with elixir-db) for point in line.points: pass varray.add_line(line) #else: # raise Exception varray.id = -1 return varray
def match_line(line): db0 = time.clock() dbLines = DBLine.getAll() allLines = [] for dbrecord in dbLines: allLines.append(dbrecord.to_numpy_array()) log.debug('m_l db: '+str(time.clock()-db0)+'s') py0 = time.clock() result = pooling.run(allLines,line.to_numpy_array()) ## symbol = pooling.MPLine(allLines) ## lines = symbol.matchLine(line.to_numpy_array()) log.debug('m_l py: '+str(time.clock()-py0)+'s') pop0 = time.clock() #build set (might be buggy!) log.info('found %d matches out of %d records!'%(len(result),len(dbLines))) resultSet = set() for recordNumber in result: resultSet.add(dbLines[recordNumber].id) response = populate_lines(line, resultSet) log.debug('m_l pop: '+str(time.clock()-pop0)+'s') log.debug('m_l total: '+str(time.clock()-db0)+'s') return response