def send(self, nid, data): try: if nodes.has_key(nid): if nodes[nid].has_key('cosm'): feed = str(nodes[nid]['cosm']['feed']['id']) for val, typ in zip(data, nodes[nid]['data']): if nodes[nid]['cosm'].has_key(typ): stream = nodes[nid]['cosm'][typ] if isinstance(val, float): self.ccomm.streamupdate(feed, stream, round(val, cosm_prec)) else: self.ccomm.streamupdate(feed, stream, val) except KeyError: pass # TODO - log errors in config
def main(infile, outfile, fromline=0): fin = open(infile, 'r') fout = open(outfile, 'w') fseek = open(log_path + '/db_progress', 'w') fout.write("USE %s;\n" % database) # read in file i = 0 # line counter for l in fin: if i < fromline: i += 1 continue # skip lines before fromline if 'OK' in l: date = l[0:10] time = l[11:19] timestamp = "'" + date + ' ' + time + "'" packet = l[28:].strip() (nid, data) = Decoder.decode(packet) if data: if nodes.has_key(nid): table = nodes[nid]['db']['table'] fieldstring = ', '.join(table['fields']) stringdata = [timestamp] for d in data: stringdata.append("'" + str(d) + "'") valstring = ', '.join(stringdata) fout.write("INSERT INTO %s (%s) VALUES (%s);\n" % (table['name'], fieldstring, valstring)) i += 1 fseek.write(str(i)) # write last line to file fin.close() fout.close() fseek.close()
def send(cls, nid, data, timestamp=None): """send raw packet to output via a decoding of the data""" if nodes.has_key(nid): if data: for val, typ in zip(data, nodes[nid]['data']): cls._output(nid, val, typ, timestamp)