def getmainInfo(dataframe): length = max(dataframe['dist']) tottime = max(dataframe['duration']) dateandtime = dataframe['time'][0] stopframe = (dataframe[dataframe['speed']<0.50][['duration']].index) stoptime = sum(dataframe['duration'].diff()[stopframe]) walktime = tottime - stoptime average_speed = length/walktime pausefaktor = stoptime/tottime ele_min = min(dataframe['ele']) ele_max = max(dataframe['ele']) elediff = ele_max-ele_min climbing = reducedElePoints(dataframe) steepness = climbing/(length/2) climbingrate = climbing/(walktime/2) kupert_faktor = climbing/elediff topptur_faktor = elediff/ele_max info = dict() info['length'] = round(length/1000,2) #km info['dateandtime'] = dateandtime info['tottime'] = dtt(seconds=tottime) info['stop_time'] = dtt(seconds=stoptime) info['walk_time'] = dtt(seconds=walktime) info['pause_faktor'] = round(pausefaktor*100,1) info['avg_speed'] = round(average_speed*3.6,2) info['elediff'] = round(elediff,1) info['climbing'] = round(climbing,1) info['steepness'] = round(steepness*1000,1) info['climbingrate'] = round(climbingrate*60,1) info['kupert_faktor'] = round(kupert_faktor,2) info['topptur_faktor'] = round(topptur_faktor*100,1) return info
def copyGPX(filename): """ Reads a GPX file, renames the file and saves it in a different folder """ f = open(filename, encoding='utf-8') ns = findNamespace(f) xml = etree.parse(f) f.close() point = xml.find(ns + "trk/" + ns + "trkseg/" + ns + "trkpt") startlat = float(point.attrib['lat']) startlon = float(point.attrib['lon']) starttime = normalizetimedata(point.find(ns + 'time').text) loc = googleLocation(startlat, startlon) timezone = googleTimezone(startlat, startlon, starttime) newfilename = createfilename(loc, starttime, timezone, 'gpx') trkname = xml.find(ns + "trk/" + ns + "name") trkname.text = str(starttime + dtt(seconds=timezone))[:16] fullFilePath = 'C:\\python\\testdata\\tcxnew\\{}'.format(newfilename) f = open(fullFilePath, 'wb') f.write(etree.tostring(xml)) f.close() return fullFilePath
def copyGPX2(originalFile, saveFilepath, newFilename): """ Reads a GPX file, renames the file and saves it in a different folder """ f = open(originalFile, encoding='utf-8') ns = findNamespace(f) xml = etree.parse(f) f.close() point = xml.find(ns + "trk/" + ns + "trkseg/" + ns + "trkpt") startlat = float(point.attrib['lat']) startlon = float(point.attrib['lon']) starttime = normalizetimedata(point.find(ns + 'time').text) timezone = googleTimezone(startlat, startlon, starttime) try: trkname = xml.find(ns + "trk/" + ns + "name") trkname.text = str(starttime + dtt(seconds=timezone))[:16] except: pass fullFilePath = saveFilepath + '\\' + newFilename f = open(fullFilePath, 'wb') f.write(etree.tostring(xml)) f.close() return 0 #fullFilePath
def init_powersaving(self): self.brightness = Config.get("settings.brightness") self.normal_brightness = self.brightness self.finish_init = datetime.now() + timedelta(seconds=5) start = Config.get("settings.powersaving.start", "01:00") end = Config.get("settings.powersaving.end", "07:00") self.powersaving_brightness = Config.get( "settings.powersaving.brightness", 0) self.powersaving_start = dtt(hour=int(start[:2]), minute=int(start[3:5])) self.powersaving_end = dtt(hour=int(end[:2]), minute=int(end[3:5])) self.update_powersaving(datetime.now())
def createTotStat(): """ Creates a placeholder for total stat data. """ totstat = dict() totstat['tot_length'] = 0 totstat['tot_antall_besteget'] = 0 totstat['tot_elevation'] = 0 totstat['tot_tottid'] = dtt(seconds=0) return totstat
def get_simulation_time(sim_min): time = '09:00' h, m = map(int, time.split(':')) init_time = dtt(hour=h, minute=m) timdelta = td(minutes=sim_min) tmp_datetime = datetime.datetime.combine(datetime.date(1, 1, 1), init_time) time2 = (tmp_datetime + timdelta).time() return time2.strftime("%I:%M %p")
def getmainInfo(dataframe): print('Number of points:', len(dataframe)) length = dataframe['dist'].max() tottime = max(dataframe['duration']) length = dataframe['dist'].max() tottime = max(dataframe['duration']) dateandtime = dataframe['time'][0] stopframe = (dataframe[dataframe['speed'] < 0.2777][['duration']].index) stoptime = sum(dataframe['duration'].diff()[stopframe]) walktime = tottime - stoptime average_speed = length / walktime pausefaktor = stoptime / tottime ele_min = dataframe['ele'].min() ele_max = dataframe['ele'].max() elediff = calcEleDiff(ele_min, ele_max) climbing = getClimbingHeightGPS(dataframe) steepness = climbing / (length / 2) climbingrate = climbing / (walktime / 2) try: kupert_faktor = climbing / elediff topptur_faktor = elediff / ele_max except: kupert_faktor = 0 topptur_faktor = 0 info = dict() info['length'] = round(length / 1000, 2) #km info['dateandtime'] = dateandtime info['tottime'] = dtt(seconds=tottime) info['stop_time'] = dtt(seconds=stoptime) info['walk_time'] = dtt(seconds=walktime) info['pause_faktor'] = round(pausefaktor * 100, 1) info['avg_speed'] = round(average_speed * 3.6, 2) info['elediff'] = round(elediff, 1) info['climbing'] = round(climbing, 1) info['steepness'] = round(steepness * 1000, 1) info['climbingrate'] = round(climbingrate * 60, 1) info['kupert_faktor'] = round(kupert_faktor, 2) info['topptur_faktor'] = round(topptur_faktor * 100, 1) return info
def getmainInfoTCX(dataframe): length = max(dataframe['dist']) tottime = dataframe['time'].max() - dataframe['time'].min() dateandtime = dataframe['time'][0] climbing = gpxtricks.getClimbingHeightGPS(dataframe) stopframe = (dataframe[dataframe['speed'] < 0.4167][['duration']].index) stoptime = sum(dataframe['duration'].diff()[stopframe]) walktime = tottime.total_seconds() - stoptime info = dict() info['length'] = round(length / 1000, 2) #km info['dateandtime'] = dateandtime info['tottime'] = tottime info['walk_time'] = dtt(seconds=walktime) info['avg_speed'] = length / walktime * 3.6 info['climbing'] = round(climbing, 1) info['activity'] = '' info['health'] = '' info['comment'] = '' info['sone1'], info['sone2'], info['sone3'], info['sone4'], info[ 'sone5'] = getTCXheartzone(dataframe) return info
def copyTCX2(originalFile, saveFilepath, newFilename): """ Reads a TCX file, renames the file and saves it in a different folder """ f = open(originalFile, encoding='utf-8') ns = findNamespace(f) xml = etree.parse(f) f.close() rawdata = findTCXFirstPoint(xml, ns) pdata = normalizedata(rawdata['rawlat'], rawdata['rawlon'], rawdata['rawtime']) loc = googleLocation(pdata['lat'], pdata['lon']) timezone = googleTimezone(pdata['lat'], pdata['lon'], pdata['time']) trkname = xml.find(ns + "Activities/" + ns + "Activity/" + ns + "Id") trkname.text = str(pdata['time'] + dtt(seconds=timezone))[:16] fullFilePath = saveFilepath + '\\' + newFilename f = open(fullFilePath, 'wb') f.write(etree.tostring(xml)) f.close() return fullFilePath
def copyTCX(filename): """ Reads a TCX file, renames the file and saves it in a different folder """ f = open(filename, encoding='utf-8') ns = findNamespace(f) xml = etree.parse(f) f.close() rawdata = findTCXFirstPoint(xml, ns) pdata = normalizedata(rawdata['rawlat'], rawdata['rawlon'], rawdata['rawtime']) loc = googleLocation(pdata['lat'], pdata['lon']) timezone = googleTimezone(pdata['lat'], pdata['lon'], pdata['time']) newfilename = createfilename(loc, pdata['time'], timezone, 'tcx') trkname = xml.find(ns + "Activities/" + ns + "Activity/" + ns + "Id") trkname.text = str(pdata['time'] + dtt(seconds=timezone))[:16] fullFilePath = 'C:\\python\\testdata\\tcxnew\\{}'.format(newfilename) f = open(fullFilePath, 'wb') f.write(etree.tostring(xml)) f.close() return fullFilePath
def handle (self, message): # there are three things this app deals with primarily: # registration, pin setup, and testing # but we'll also use it to circumvent some logic in the tree # app with a few custom codes. if message.text.lower() == "iavi uganda" or message.text.lower() == "iavi kenya": # if they are allowed to participate, return false so # that the message propagates to the tree app. If they # aren't this will come back as handled and the tree app # will never see it. # ASSUMES ORDERING OF APPS AND THAT THIS IS BEFORE TREE return not self._allowed_to_participate(message) # we'll be using the language in all our responses so # keep it handy language = get_language_code(message.persistant_connection) # check pin conditions and process if they match if message.reporter and message.reporter.pk in self.pending_pins: return self._process_pin(message) # registration block # first make sure the string starts and ends with the *# - #* combination match = re.match(r"^\*\#(.*?)\#\*$", message.text) if match: self.info("Message matches! %s", message) body_groups = match.groups()[0].split("#") if len(body_groups)== 3 and body_groups[0] == "8377": # this is the testing format # this is the (extremely ugly) format of testing # *#8377#<Site Number>#<Last 4 Digits of Participant ID>#* # TODO: implement testing code, site, id = body_groups alias = IaviReporter.get_alias(site, id) try: # lookup the user in question and initiate the tree # sequence for them. If there are errors, respond # with them user = IaviReporter.objects.get(alias=alias) errors = self._initiate_tree_sequence(user, message.persistant_connection) if errors: message.respond(errors) except IaviReporter.DoesNotExist: message.respond(_(strings["unknown_user"], language) % {"alias":id}) return True else: # assume this is the registration format # this is the (extremely ugly) format of registration # time is optional # *#<Country/Language Group>#<Site Number>#<Last 3 Digits of Participant ID>#<time?>#* if len(body_groups) == 3: language, site, id = body_groups study_time = "1600" elif len(body_groups) == 4: language, site, id, study_time = body_groups else: message.respond(_(strings["unknown_format"], get_language_code(message.persistant_connection))) # validate the format of the id, existence of location if not re.match(r"^\d{3}$", id): message.respond(_(strings["id_format"], get_language_code(message.persistant_connection)) % {"alias" : id}) return True try: location = Location.objects.get(code=site) except Location.DoesNotExist: message.respond(_(strings["unknown_location"], get_language_code(message.persistant_connection)) % {"alias" : id, "location" : site}) return True # TODO: validate the language # validate and get the time object if re.match(r"^\d{4}$", study_time): hour = int(study_time[0:2]) minute = int(study_time[2:4]) if hour < 0 or hour >= 24 or minute < 0 or minute >= 60: message.respond(_(strings["time_format"], get_language_code(message.persistant_connection)) % {"alias" : id, "time" : study_time}) return real_time = dtt(hour, minute) else: message.respond(_(strings["time_format"], get_language_code(message.persistant_connection)) % {"alias" : id, "time" : study_time}) return # user ids are unique per-location so use location-id # as the alias alias = IaviReporter.get_alias(location.code, id) # make sure this isn't a duplicate alias if len(IaviReporter.objects.filter(alias=alias)) > 0: message.respond(_(strings["already_registered"], language) % {"alias": id, "location":location.code}) return True # create the reporter object for this person reporter = IaviReporter(alias=alias, language=language, location=location, registered=message.date) reporter.save() # create the study participant for this too. Assume they're starting # tomorrow and don't set a stop date. start_date = (datetime.today() + timedelta(days=1)).date() participant = StudyParticipant.objects.create(reporter=reporter, start_date = start_date, notification_time = real_time) # also attach the reporter to the connection message.persistant_connection.reporter=reporter message.persistant_connection.save() message.respond(_(strings["registration_complete"], language) % {"alias": id }) # also send the PIN request and add this user to the # pending pins self.pending_pins[reporter.pk] = None message.respond(_(strings["pin_request"], language)) else: self.info("Message doesn't match. %s", message)
lotname = 'wustl_millbrook' def space_list(min, max, items) : for i in range(items) : yield random.randint(min,max) simulating = True while simulating : host = httplib.HTTPConnection(hostname) print 'PUT to',hostname,'in lot',lotname,'...', # generage a random number of spaces to change spaces = [] changed = random.randint(1, 10) now = dtdt.now() six_oclock = dtdt.combine(now.date(), dtt(6, 00)) seven_oclock = dtdt.combine(now.date(), dtt(7, 00)) twelve_oclock = dtdt.combine(now.date(), dtt(12, 00)) thirteen_oclock = dtdt.combine(now.date(), dtt(13, 00)) eighteen_oclock = dtdt.combine(now.date(), dtt(18, 00)) nineteen_oclock = dtdt.combine(now.date(), dtt(19, 00)) twentytwo_oclock = dtdt.combine(now.date(), dtt(22, 00)) five_oclock = dtdt.combine(now.date(), dtt(5, 00)) if six_oclock <= now <= seven_oclock : weight = 3 elif twelve_oclock <= now <= thirteen_oclock : changed *= 2 weight = 3 elif eighteen_oclock <= now <= nineteen_oclock : weight = 3 elif now >= twentytwo_oclock or now <= five_oclock :
def createfilename(location, time, timezone=0, fileextension='.gpx'): normtime = str(time + dtt(seconds=timezone)) normtime = normtime[:16] normtime = normtime.replace(':', '') newfilename = '{0} {1}{2}'.format(normtime, location, fileextension) return newfilename
def handle(self, message): # there are three things this app deals with primarily: # registration, pin setup, and testing # but we'll also use it to circumvent some logic in the tree # app with a few custom codes. if message.text.lower() == "iavi uganda" or message.text.lower( ) == "iavi kenya": # if they are allowed to participate, return false so # that the message propagates to the tree app. If they # aren't this will come back as handled and the tree app # will never see it. # ASSUMES ORDERING OF APPS AND THAT THIS IS BEFORE TREE return not self._allowed_to_participate(message) # we'll be using the language in all our responses so # keep it handy language = get_language_code(message.persistant_connection) # check pin conditions and process if they match if message.reporter and message.reporter.pk in self.pending_pins: return self._process_pin(message) # registration block # first make sure the string starts and ends with the *# - #* combination match = re.match(r"^\*\#(.*?)\#\*$", message.text) if match: self.info("Message matches! %s", message) body_groups = match.groups()[0].split("#") if len(body_groups) == 3 and body_groups[0] == "8377": # this is the testing format # this is the (extremely ugly) format of testing # *#8377#<Site Number>#<Last 4 Digits of Participant ID>#* # TODO: implement testing code, site, id = body_groups alias = IaviReporter.get_alias(site, id) try: # lookup the user in question and initiate the tree # sequence for them. If there are errors, respond # with them user = IaviReporter.objects.get(alias=alias) errors = self._initiate_tree_sequence( user, message.persistant_connection) if errors: message.respond(errors) except IaviReporter.DoesNotExist: message.respond( _(strings["unknown_user"], language) % {"alias": id}) return True else: # assume this is the registration format # this is the (extremely ugly) format of registration # time is optional # *#<Country/Language Group>#<Site Number>#<Last 3 Digits of Participant ID>#<time?>#* if len(body_groups) == 3: language, site, id = body_groups study_time = "1600" elif len(body_groups) == 4: language, site, id, study_time = body_groups else: message.respond( _(strings["unknown_format"], get_language_code(message.persistant_connection))) # validate the format of the id, existence of location if not re.match(r"^\d{3}$", id): message.respond( _(strings["id_format"], get_language_code(message.persistant_connection)) % {"alias": id}) return True try: location = Location.objects.get(code=site) except Location.DoesNotExist: message.respond( _(strings["unknown_location"], get_language_code(message.persistant_connection)) % { "alias": id, "location": site }) return True # TODO: validate the language # validate and get the time object if re.match(r"^\d{4}$", study_time): hour = int(study_time[0:2]) minute = int(study_time[2:4]) if hour < 0 or hour >= 24 or minute < 0 or minute >= 60: message.respond( _(strings["time_format"], get_language_code(message.persistant_connection)) % { "alias": id, "time": study_time }) return real_time = dtt(hour, minute) else: message.respond( _(strings["time_format"], get_language_code(message.persistant_connection)) % { "alias": id, "time": study_time }) return # user ids are unique per-location so use location-id # as the alias alias = IaviReporter.get_alias(location.code, id) # make sure this isn't a duplicate alias if len(IaviReporter.objects.filter(alias=alias)) > 0: message.respond( _(strings["already_registered"], language) % { "alias": id, "location": location.code }) return True # create the reporter object for this person reporter = IaviReporter(alias=alias, language=language, location=location, registered=message.date) reporter.save() # create the study participant for this too. Assume they're starting # tomorrow and don't set a stop date. start_date = (datetime.today() + timedelta(days=1)).date() participant = StudyParticipant.objects.create( reporter=reporter, start_date=start_date, notification_time=real_time) # also attach the reporter to the connection message.persistant_connection.reporter = reporter message.persistant_connection.save() message.respond( _(strings["registration_complete"], language) % {"alias": id}) # also send the PIN request and add this user to the # pending pins self.pending_pins[reporter.pk] = None message.respond(_(strings["pin_request"], language)) else: self.info("Message doesn't match. %s", message)
def validate(self, *args, **kwargs): message = args[0] form_entry = args[1] data = form_entry.to_dict() if form_entry.form.code.abbreviation == "register": language = data["language"] site = data["location"] id = data["study_id"] # time is optional study_time = data["time"] if not study_time: study_time = "1600" # validate the format of the id, existence of location if not re.match(r"^\d{3}$", id): return [(_(strings["id_format"], get_language_code(message.persistant_connection)) % {"alias" : id})] try: location = Location.objects.get(code=site) except Location.DoesNotExist: return[(_(strings["unknown_location"], get_language_code(message.persistant_connection)) % {"alias" : id, "location" : site})] # TODO: validate the language # validate and get the time object if re.match(r"^\d{4}$", study_time): hour = int(study_time[0:2]) minute = int(study_time[2:4]) if hour < 0 or hour >= 24 or minute < 0 or minute >= 60: return [(_(strings["time_format"], get_language_code(message.persistant_connection)) % {"alias" : id, "time" : study_time})] real_time = dtt(hour, minute) else: return [(_(strings["time_format"], get_language_code(message.persistant_connection)) % {"alias" : id, "time" : study_time})] # user ids are unique per-location so use location-id # as the alias alias = IaviReporter.get_alias(location.code, id) # make sure this isn't a duplicate alias if len(IaviReporter.objects.filter(alias=alias)) > 0: return [(_(strings["already_registered"], language) % {"alias": id, "location":location.code})] return True data["alias"] = alias data["location"] = location data["time"] = real_time # all fields were present and correct, so copy them into the # form_entry, for "actions" to pick up again without re-fetching form_entry.reg_data = data return [] elif form_entry.form.code.abbreviation == "test": print "test!" print data site = data["location"] id = data["study_id"] alias = IaviReporter.get_alias(site, id) try: # make sure the user in question exists. If not, # respond with an error user = IaviReporter.objects.get(alias=alias) # set some data in the form_entry so we have easy # access to it from within actions data["reporter"] = user data["alias"] = alias form_entry.test_data = data except IaviReporter.DoesNotExist: return [(_(strings["unknown_user"], language) % {"alias":id})]