Changeset 394
- Timestamp:
- 05/11/12 14:28:38 (9 years ago)
- Location:
- trunk/Puzzlebox/Synapse
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Puzzlebox/Synapse/Interface.py
r391 r394 7 7 8 8 __changelog__ = """\ 9 Last Update: 2012.0 4.039 Last Update: 2012.05.11 10 10 """ 11 11 … … 164 164 165 165 166 self.activePlugins = [ ]166 self.activePlugins = [self] 167 167 168 168 … … 524 524 parent=self) 525 525 526 for header in self.synapseServer.customDataHeaders: 527 if header not in self.customDataHeaders: 528 self.customDataHeaders.append(header) 529 526 530 self.synapseServer.start() 527 531 … … 531 535 def stopThinkGearConnectService(self): 532 536 533 pass 537 for header in self.synapseServer.customDataHeaders: 538 if header in self.customDataHeaders: 539 del(self.customDataHeaders[header]) 534 540 535 541 … … 563 569 parent=self) 564 570 571 for header in self.synapseServer.customDataHeaders: 572 if header not in self.customDataHeaders: 573 self.customDataHeaders.append(header) 574 565 575 self.synapseServer.start() 566 576 … … 596 606 #self.progressBarAttention.setEnabled(True) 597 607 #self.progressBarMeditation.setEnabled(True) 608 609 for header in self.synapseServer.customDataHeaders: 610 if header in self.customDataHeaders: 611 del(self.customDataHeaders[header]) 598 612 599 613 … … 865 879 ################################################################## 866 880 881 def processPacketForExport(self, packet={}, output={}): 882 883 if self.synapseServer != None: 884 output = self.synapseServer.processPacketForExport(packet, output) 885 886 return(output) 887 888 889 ################################################################## 890 867 891 def stop(self): 868 892 -
trunk/Puzzlebox/Synapse/Session.py
r393 r394 405 405 ################################################################## 406 406 407 #def exportDataToCSV(self, parent=None, source=None, target=None):408 409 #output = ''410 411 #if self.synapseServer != None:412 ##output = self.synapseServer.exportDataToCSV(parent=self.parent, source=self)413 #output = self.synapseServer.exportDataToCSV(parent=parent, source=source, target=target)414 415 #else:416 417 #if self.DEBUG:418 #print "ERROR: exportDataToCSV exists in synapseServer object which is not in use"419 420 #return(output)421 422 423 ##################################################################424 425 407 def exportDataToCSV(self, parent=None, source=None, target=None): 426 408 … … 464 446 465 447 headers = 'Date,Time' 466 #headers = headers + ',' 467 #headers = 'Date,Time,Attention,Meditation,Signal Level,Delta,Theta,Low Alpha,High Alpha,Low Beta,High Beta,Low Gamma,Mid Gamma' 468 #headers = headers + 'Attention,Meditation,Signal Level,Delta,Theta,Low Alpha,High Alpha,Low Beta,High Beta,Low Gamma,Mid Gamma' 469 #headers = self.customDataHeaders 448 470 449 471 450 customDataHeaders = [] … … 513 492 for plugin in parent.activePlugins: 514 493 if plugin.customDataHeaders != []: 515 #try: 516 csv[timestamp] = plugin.processPacketForExport(output=csv[timestamp], packet=packet) 517 518 #print "csv[timestamp]:", 519 #print csv[timestamp] 520 #except Exception, e: 521 #if self.DEBUG: 522 #print "ERROR: [Synapse:Session] Exception calling processPacketForExport on", 523 #print plugin.name 524 525 526 #csv[timestamp]['Attention'] = '' 527 #csv[timestamp]['Meditation'] = '' 528 #csv[timestamp]['Signal Level'] = '' 529 #csv[timestamp]['Delta'] = '' 530 #csv[timestamp]['Theta'] = '' 531 #csv[timestamp]['Low Alpha'] = '' 532 #csv[timestamp]['High Alpha'] = '' 533 #csv[timestamp]['Low Beta'] = '' 534 #csv[timestamp]['High Beta'] = '' 535 #csv[timestamp]['Low Gamma'] = '' 536 #csv[timestamp]['Mid Gamma'] = '' 537 538 #for header in customDataHeaders: 539 #csv[timestamp][header] = '' 540 541 542 #if 'eSense' in packet.keys(): 543 #if 'attention' in packet['eSense'].keys(): 544 #csv[timestamp]['Attention'] = packet['eSense']['attention'] 545 #if 'meditation' in packet['eSense'].keys(): 546 #csv[timestamp]['Meditation'] = packet['eSense']['meditation'] 547 548 #if 'poorSignalLevel' in packet.keys(): 549 #csv[timestamp]['Signal Level'] = packet['poorSignalLevel'] 550 551 #if 'eegPower' in packet.keys(): 552 #if 'delta' in packet['eegPower'].keys(): 553 #csv[timestamp]['Delta'] = packet['eegPower']['delta'] 554 #if 'theta' in packet['eegPower'].keys(): 555 #csv[timestamp]['Theta'] = packet['eegPower']['theta'] 556 #if 'lowAlpha' in packet['eegPower'].keys(): 557 #csv[timestamp]['Low Alpha'] = packet['eegPower']['lowAlpha'] 558 #if 'highAlpha' in packet['eegPower'].keys(): 559 #csv[timestamp]['High Alpha'] = packet['eegPower']['highAlpha'] 560 #if 'lowBeta' in packet['eegPower'].keys(): 561 #csv[timestamp]['Low Beta'] = packet['eegPower']['lowBeta'] 562 #if 'highBeta' in packet['eegPower'].keys(): 563 #csv[timestamp]['High Beta'] = packet['eegPower']['highBeta'] 564 #if 'lowGamma' in packet['eegPower'].keys(): 565 #csv[timestamp]['Low Gamma'] = packet['eegPower']['lowGamma'] 566 #if 'highGamma' in packet['eegPower'].keys(): 567 #csv[timestamp]['Mid Gamma'] = packet['eegPower']['highGamma'] 494 try: 495 csv[timestamp] = plugin.processPacketForExport(output=csv[timestamp], packet=packet) 496 except Exception, e: 497 if self.DEBUG: 498 print "ERROR: [Synapse:Session] Exception calling processPacketForExport on", 499 print plugin.name 568 500 569 501 … … 578 510 579 511 580 #print csv581 582 583 512 if scrub_data: 584 513 csv = self.scrubData(csv, truncate_csv_timezone, source=source) … … 591 520 592 521 for timestamp in timestamps: 593 594 #row = '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % \595 #(csv[timestamp]['Date'], \596 #csv[timestamp]['Time'], \597 #csv[timestamp]['Attention'], \598 #csv[timestamp]['Meditation'], \599 #csv[timestamp]['Signal Level'], \600 #csv[timestamp]['Delta'], \601 #csv[timestamp]['Theta'], \602 #csv[timestamp]['Low Alpha'], \603 #csv[timestamp]['High Alpha'], \604 #csv[timestamp]['Low Beta'], \605 #csv[timestamp]['High Beta'], \606 #csv[timestamp]['Low Gamma'], \607 #csv[timestamp]['Mid Gamma'])608 609 610 #print csv[timestamp]611 522 612 523 row = '%s,%s' % \ -
trunk/Puzzlebox/Synapse/ThinkGear/Server.py
r393 r394 539 539 ################################################################## 540 540 541 #def exportDataToCSV(self, parent=None, source=None, target=None):542 543 ## handle importing class from multiple sources544 #if parent == None:545 #if self.parent == None:546 #parent = self547 #else:548 #parent = self.parent549 550 #if source == None:551 #if self.parent == None:552 #source = self553 #else:554 #source = self.parent555 556 #if target == None:557 #if self.parent == None:558 #target = self559 #else:560 #target = self.parent561 562 #try:563 #truncate_csv_timezone = target.configuration.EXPORT_CSV_TRUNCATE_TIMEZONE564 #except:565 #truncate_csv_timezone = False566 567 568 #if not self.emulate_headset_data:569 ## NOTE: no need to scrub emulated data570 #try:571 #scrub_data = target.configuration.EXPORT_CSV_SCRUB_DATA572 #except:573 #scrub_data = False574 #else:575 #scrub_data = False576 577 ##headers = 'Date,Time'578 #headers = 'Date,Time,Attention,Meditation,Signal Level,Delta,Theta,Low Alpha,High Alpha,Low Beta,High Beta,Low Gamma,Mid Gamma'579 ##headers = self.customDataHeaders580 581 #customDataHeaders = []582 #for header in parent.customDataHeaders:583 #customDataHeaders.append(header)584 #for plugin in parent.activePlugins:585 #for header in plugin.customDataHeaders:586 #customDataHeaders.append(header)587 588 #for each in customDataHeaders:589 #headers = headers + ',%s' % each590 591 #headers = headers + '\n'592 593 594 #csv = {}595 596 #for packet in source.packets['signals']:597 598 599 #if 'rawEeg' in packet.keys():600 #continue601 602 #if packet['timestamp'] not in csv.keys():603 604 #if 'blinkStrength' in packet.keys():605 ## Skip any blink packets from log606 #continue607 608 609 #timestamp = packet['timestamp']610 ##(date, localtime) = self.parseTimeStamp(timestamp, \611 ##truncate_time_zone=truncate_csv_timezone)612 #(date, localtime) = source.parseTimeStamp(timestamp, \613 #truncate_time_zone=truncate_csv_timezone)614 615 #csv[timestamp] = {}616 #csv[timestamp]['Date'] = date617 #csv[timestamp]['Time'] = localtime618 #csv[timestamp]['Attention'] = ''619 #csv[timestamp]['Meditation'] = ''620 #csv[timestamp]['Signal Level'] = ''621 #csv[timestamp]['Delta'] = ''622 #csv[timestamp]['Theta'] = ''623 #csv[timestamp]['Low Alpha'] = ''624 #csv[timestamp]['High Alpha'] = ''625 #csv[timestamp]['Low Beta'] = ''626 #csv[timestamp]['High Beta'] = ''627 #csv[timestamp]['Low Gamma'] = ''628 #csv[timestamp]['Mid Gamma'] = ''629 630 #for header in customDataHeaders:631 #csv[timestamp][header] = ''632 633 634 #if 'eSense' in packet.keys():635 #if 'attention' in packet['eSense'].keys():636 #csv[timestamp]['Attention'] = packet['eSense']['attention']637 #if 'meditation' in packet['eSense'].keys():638 #csv[timestamp]['Meditation'] = packet['eSense']['meditation']639 640 #if 'poorSignalLevel' in packet.keys():641 #csv[timestamp]['Signal Level'] = packet['poorSignalLevel']642 643 #if 'eegPower' in packet.keys():644 #if 'delta' in packet['eegPower'].keys():645 #csv[timestamp]['Delta'] = packet['eegPower']['delta']646 #if 'theta' in packet['eegPower'].keys():647 #csv[timestamp]['Theta'] = packet['eegPower']['theta']648 #if 'lowAlpha' in packet['eegPower'].keys():649 #csv[timestamp]['Low Alpha'] = packet['eegPower']['lowAlpha']650 #if 'highAlpha' in packet['eegPower'].keys():651 #csv[timestamp]['High Alpha'] = packet['eegPower']['highAlpha']652 #if 'lowBeta' in packet['eegPower'].keys():653 #csv[timestamp]['Low Beta'] = packet['eegPower']['lowBeta']654 #if 'highBeta' in packet['eegPower'].keys():655 #csv[timestamp]['High Beta'] = packet['eegPower']['highBeta']656 #if 'lowGamma' in packet['eegPower'].keys():657 #csv[timestamp]['Low Gamma'] = packet['eegPower']['lowGamma']658 #if 'highGamma' in packet['eegPower'].keys():659 #csv[timestamp]['Mid Gamma'] = packet['eegPower']['highGamma']660 661 #for header in customDataHeaders:662 #if 'custom' in packet.keys() and \663 #header in packet['custom'].keys():664 #csv[timestamp][header] = packet['custom'][header]665 666 667 #if scrub_data:668 #csv = self.scrubData(csv, truncate_csv_timezone, source=source)669 670 671 #output = headers672 673 #csv_keys = csv.keys()674 #csv_keys.sort()675 676 #for key in csv_keys:677 678 #row = '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % \679 #(csv[key]['Date'], \680 #csv[key]['Time'], \681 #csv[key]['Attention'], \682 #csv[key]['Meditation'], \683 #csv[key]['Signal Level'], \684 #csv[key]['Delta'], \685 #csv[key]['Theta'], \686 #csv[key]['Low Alpha'], \687 #csv[key]['High Alpha'], \688 #csv[key]['Low Beta'], \689 #csv[key]['High Beta'], \690 #csv[key]['Low Gamma'], \691 #csv[key]['Mid Gamma'])692 693 #for header in customDataHeaders:694 #row = row + ',%s' % csv[key][header]695 696 #row = row + '\n'697 698 #output = output + row699 700 701 #return(output)702 703 704 ##################################################################705 706 #def scrubData(self, csv, truncate_csv_timezone=False, source=None):707 708 ## If there are missing packets, repeat a given packet once per missing709 ## second until there is a gap between 1 and 2 seconds, in which case710 ## produce a final duplicate packet at the mid-point between the packets711 712 #if self.DEBUG:713 #print "INFO: Scrubbing Data"714 715 #if source == None:716 #if self.parent == None:717 #source = self718 #else:719 #source = self.parent720 721 #last_time = None722 #last_recorded_time = None723 724 #output = {}725 726 #csv_keys = csv.keys()727 #csv_keys.sort()728 729 #for key in csv_keys:730 731 #timestamp = key732 733 #if csv[key]['Attention'] == '':734 #continue735 736 #if last_time == None:737 ## First entry in log738 #last_time = timestamp739 #last_recorded_time = timestamp740 #output[key] = csv[key]741 #continue742 743 #else:744 745 ##time_difference = timestamp - last_time746 #time_difference = timestamp - last_recorded_time747 748 #if (time_difference <= 1) and \749 #(time_difference >= PACKET_MINIMUM_TIME_DIFFERENCE_THRESHOLD):750 ## Skip packets within the correct time threshold751 #last_time = timestamp752 #last_recorded_time = timestamp753 #output[key] = csv[key]754 #continue755 756 #else:757 758 #if self.DEBUG > 1:759 #print "time_difference:",760 #print time_difference761 #print "timestamp:",762 #print source.parseTimeStamp(timestamp)[-1].split(' ')[0]763 #print "last_time:",764 #print source.parseTimeStamp(last_time)[-1].split(' ')[0]765 #print "last_recorded_time:",766 #print source.parseTimeStamp(last_recorded_time)[-1].split(' ')[0]767 768 769 #new_packet = csv[key].copy()770 771 #if time_difference >= 2:772 773 ###new_time = last_time + 1774 ##new_time = last_recorded_time + 1775 776 #count = int(time_difference)777 #while count >= 1:778 #new_packet = csv[key].copy()779 #new_time = last_recorded_time + 1780 #(date, formatted_new_time) = source.parseTimeStamp(new_time, \781 #truncate_time_zone=truncate_csv_timezone)782 #new_packet['Time'] = formatted_new_time783 #last_recorded_time = new_time784 #last_time = timestamp785 #output[new_time] = new_packet786 #count = count - 1787 #continue788 789 #elif time_difference < PACKET_MINIMUM_TIME_DIFFERENCE_THRESHOLD:790 ## Spread out "bunched up" packets791 ##new_time = last_time + 1792 #new_time = last_recorded_time + 1793 794 795 #elif (time_difference < 2) and (time_difference > 1):796 797 ##new_time = last_time + ((last_time - timestamp) / 2)798 ##new_time = last_recorded_time + ((last_recorded_time - timestamp) / 2)799 ##new_time = last_time + 1800 #new_time = last_recorded_time + 1801 802 803 #(date, formatted_new_time) = source.parseTimeStamp(new_time, \804 #truncate_time_zone=truncate_csv_timezone)805 806 #new_packet['Time'] = formatted_new_time807 808 ##last_time = new_time809 #last_recorded_time = new_time810 #last_time = timestamp811 #output[new_time] = new_packet812 813 #if self.DEBUG > 1:814 #print "WARN: Scrubbing new packet:",815 #print new_packet816 #print817 818 819 #return(output)820 821 822 ##################################################################823 824 541 def setPacketCount(self, value): 825 542
Note: See TracChangeset
for help on using the changeset viewer.