Changeset 286
- Timestamp:
- 09/19/11 14:55:32 (11 years ago)
- Location:
- trunk/Puzzlebox/Synapse
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Puzzlebox/Synapse/Interface.py
r285 r286 428 428 self.processPacketThinkGear( \ 429 429 self.thinkGearConnectServer.protocol.data_packet) 430 431 432 ##################################################################433 434 def parseTimeStamp(self, timestamp, local_version=False, truncate_time_zone=False):435 436 try:437 decimal = '%f' % timestamp438 decimal = decimal.split('.')[1]439 except:440 decimal = '0'441 442 localtime = time.localtime(timestamp)443 444 if local_version:445 date = time.strftime('%x', localtime)446 localtime = time.strftime('%X', localtime)447 448 elif truncate_time_zone:449 date = time.strftime('%Y-%m-%d', localtime)450 localtime = time.strftime('%H:%M:%S', localtime)451 localtime = '%s.%s' % (localtime, decimal[:3])452 453 else:454 date = time.strftime('%Y-%m-%d', localtime)455 localtime = time.strftime('%H:%M:%S', localtime)456 localtime = '%s.%s %s' % (localtime, decimal, \457 time.strftime('%Z', time.localtime(timestamp)))458 459 460 return(date, localtime)461 430 462 431 … … 810 779 ################################################################## 811 780 781 def parseTimeStamp(self, timestamp, local_version=False, truncate_time_zone=False): 782 783 try: 784 decimal = '%f' % timestamp 785 decimal = decimal.split('.')[1] 786 except: 787 decimal = '0' 788 789 localtime = time.localtime(timestamp) 790 791 if local_version: 792 date = time.strftime('%x', localtime) 793 localtime = time.strftime('%X', localtime) 794 795 elif truncate_time_zone: 796 date = time.strftime('%Y-%m-%d', localtime) 797 localtime = time.strftime('%H:%M:%S', localtime) 798 localtime = '%s.%s' % (localtime, decimal[:3]) 799 800 else: 801 date = time.strftime('%Y-%m-%d', localtime) 802 localtime = time.strftime('%H:%M:%S', localtime) 803 localtime = '%s.%s %s' % (localtime, decimal, \ 804 time.strftime('%Z', time.localtime(timestamp))) 805 806 807 return(date, localtime) 808 809 810 ################################################################## 811 812 812 def saveData(self): 813 813 … … 845 845 def exportData(self): 846 846 847 if self == None:847 if self.parent == None: 848 848 target = self 849 849 else: … … 895 895 896 896 try: 897 truncate_csv_timezone = target.configuration. TRUNCATE_CSV_TIMEZONE897 truncate_csv_timezone = target.configuration.EXPORT_CSV_TRUNCATE_TIMEZONE 898 898 except: 899 899 truncate_csv_timezone = False 900 901 try: 902 scrub_data = target.configuration.EXPORT_CSV_SCRUB_DATA 903 except: 904 scrub_data = False 905 900 906 901 907 header = 'Date,Time,Delta,Theta,Low Alpha,High Alpha,Low Beta,High Beta,Low Gamma,Mid Gamma,Attention,Meditation,Signal Level' … … 971 977 csv[timestamp][each] = packet['custom'][each] 972 978 979 980 if scrub_data: 981 csv = self.scrubData(csv, truncate_csv_timezone) 982 983 973 984 output = header 974 985 … … 1006 1017 ################################################################## 1007 1018 1019 def scrubData(self, csv, truncate_csv_timezone=False): 1020 1021 # If there are missing packets, repeat a given packet once per missing 1022 # second until there is a gap between 1 and 2 seconds, in which case 1023 # produce a final duplicate packet at the mid-point between the packets 1024 1025 last_time = None 1026 1027 output = {} 1028 1029 csv_keys = csv.keys() 1030 csv_keys.sort() 1031 1032 for key in csv_keys: 1033 1034 localtime = key 1035 1036 if last_time == None: 1037 last_time = localtime 1038 output[key] = csv[key] 1039 continue 1040 1041 else: 1042 1043 time_difference = last_time - localtime 1044 1045 if time_difference <= 1: 1046 last_time = localtime 1047 output[key] = csv[key] 1048 continue 1049 1050 else: 1051 1052 new_packet = csv[key].copy() 1053 1054 if time_difference >= 2: 1055 1056 new_time = localtime + 1 1057 1058 1059 elif (time_difference < 2) and (time_difference > 1): 1060 1061 new_time = last_time + ((last_time - localtime) / 2) 1062 1063 1064 (date, formatted_new_time) = self.parseTimeStamp(new_time, \ 1065 truncate_time_zone=truncate_csv_timezone) 1066 1067 new_packet['Time'] = formatted_new_time 1068 1069 last_time = new_time 1070 output[new_time] = new_packet 1071 1072 if self.DEBUG: 1073 print "WARN: Scrubbing new packet:", 1074 print new_packet 1075 1076 1077 return(output) 1078 1079 1080 ################################################################## 1081 1008 1082 def resetData(self): 1009 1083 -
trunk/Puzzlebox/Synapse/Protocol.py
r282 r286 750 750 751 751 if (self.parent != None): 752 753 # NOTE: is it possible this call is blocking the Protocol 754 # thread from continuing to parse data? 755 752 756 self.parent.processPacketThinkGear(process_packet) 753 757 … … 997 1001 # (1/512) * 1000 = 1.9531250 998 1002 while len(self.buffer) < length: 999 QtCore.QThread.msleep(2) 1003 try: 1004 QtCore.QThread.msleep(2) 1005 except Exception, e: 1006 #if self.DEBUG: 1007 #print "ERROR: Protocol failed to call QtCore.QThread.msleep(2) in read():", 1008 #print e 1009 pass 1000 1010 1001 1011 bytes = self.buffer[:length] … … 1013 1023 self.buffer_check_timer.stop() 1014 1024 self.read_buffer_check_timer.stop() 1025 self.buffer = '' 1015 1026 1016 1027
Note: See TracChangeset
for help on using the changeset viewer.