Exemplo n.º 1
0
    def test_data_saver(self):
        """ Test whether DataSaver class functions well """
        data_saver = DataSaver(DATA_SAVER_TEST_DIR)

        self.assertEqual(data_saver.folder, DATA_SAVER_TEST_DIR)
        with self.assertRaises(NotImplementedError):
            data_saver.save(np.array([1, 2, 3]), 'nothing')
Exemplo n.º 2
0
    def listen(self):

        # Initialize commands
        if not self.axis_data:
            self.axis_data = {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: -1.0}

        # Main listening loop
        while not rospy.is_shutdown():
            if self.curr_mode == 'manual':
                for event in pygame.event.get():
                    # Stop and start recording
                    if event.type == pygame.JOYBUTTONDOWN:
                        # Starting Recording
                        if (event.button == 2 and not self.recording):
                            rospy.loginfo("Starting recording...")
                            folder_name = str(date.today()) + "-" + str(
                                time.strftime("%H-%M-%S")) + "/"
                            self.data_saver = DataSaver(
                                '/home/nvidia/jetsonbot/src/rccar/data/' +
                                folder_name)
                            self.recording = True
                        # Stopping Recording
                        elif (event.button == 0 and self.recording):
                            rospy.loginfo("Stopping recording...")
                            del self.data_saver
                            self.recording = False
                    # Acceleration and Steering
                    elif event.type == pygame.JOYAXISMOTION:
                        self.axis_data[event.axis] = round(event.value, 2)
                        throttle = round(0.5 + self.axis_data[4] / 2.0, 5)
                        steering = round(self.axis_data[0], 5)
                        self.pub.publish(Point(throttle, steering, 0.0))
Exemplo n.º 3
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.camera = None

        self.clip_size = None
        self.ndarray_available.connect(self.clip_array)
        self.ndarray_available.connect(self.convert_to_grayscale)

        self.plugin_loader = PluginLoader()
        self.plugins = self.plugin_loader.plugins
        for plugin in self.plugins:
            try:
                plugin.message.connect(self.message)
            except:
                qDebug("Cannot connect to messages from {}".format(plugin.getName()))
        self.ndarray_available.connect(self.plugin_loader.ndarray_available)
        self.ndarray_bw_available.connect(self.plugin_loader.ndarray_bw_available)
        self.clipped_ndarray_available.connect(self.plugin_loader.clipped_ndarray_available)
        self.clipped_ndarray_bw_available.connect(self.plugin_loader.clipped_ndarray_bw_available)

        self.data_saver = DataSaver()
        self.ndarray_bw_available.connect(self.data_saver.set_array)
        self.save_file.connect(self.data_saver.save_image)
        self.data_saver.message.connect(self.message)

        # this limits the global frame rate in this program:
        self.last_frame_time = time.time()
        self.frame_interval = 0.1
Exemplo n.º 4
0
    def __init__(self, logger):
        self.serverconfig = ServerConfig('<broadcast>', 23456, 23466)
        self.data_saver = DataSaver()

        self.__carclientserverThread = CarClientServerThread(
            self.serverconfig, self.data_saver, logger)
        self.__beaconserverThread = ServerBeaconThread(self.serverconfig, 1.0,
                                                       logger)
Exemplo n.º 5
0
 def collect_data_to_disk(self):
   print("Collecting data...")
   DataSaver().save(self.scans)
   self.data_collection_in_progress = False
   print("Data collected\n")
def main(args):
    OUTPUT = args.output

    print("Running OS baseline test.\n")
    print("Make sure you have no apps running in the background.")
    print("Make sure that there is a wakelock app running.")
    print("Charging is disabled at the beginning of the test")
    print("and then enabled when we reach 5%.")

    _ = input("Press enter when ready...")
    ds = DataSaver(OUTPUT)
    ds.start()

    print("Getting Phone Model...")
    model = get_phone_model()
    print("Is the model %s correct?" % model.model)
    input("Press Enter to confirm...")

    print("Disabling charging...")
    model.disable_charging()
    input("Is it disabled?")
    print("Start time: {}".format(datetime.datetime.utcnow()))

    try:
        level = 1000
        prevcharge = 0
        prevlevel = 0
        prevtemp = 0
        while level != FINALLEVEL:
            start = time.time()

            info = parse_battery_info(get_battery_info())
            info["timestamp"] = time.time()
            ds.add(info, "batterydata")
            level = int(info["level"])

            if (prevcharge != info["Charge counter"] or prevlevel != level
                    or prevtemp != info["temperature"]):
                finish_same_line()
            write_same_line("{} | Current capacity: {}%, {}, Temp: {}".format(
                datetime.datetime.utcnow(),
                str(level),
                info["Charge counter"],
                info["temperature"],
            ))

            prevlevel = level
            prevcharge = info["Charge counter"]
            prevtemp = info["temperature"]

            end = time.time()
            telapsed = end - start

            if telapsed < RESOLUTION:
                time.sleep(RESOLUTION - telapsed)
    except Exception as e:
        model.enable_charging()
        raise

    finish_same_line()

    print("Enabling charging...")
    model.enable_charging()

    print("Stopping data saver...")
    ds.stop_running()
    print("Done.")
Exemplo n.º 7
0
 def create(self, max_iter):
     logging.info("Processing the EEG file %s", self._info['eeg']['filename'])
     eeg = EEG(data_reader=matlab_data_reader).read(self._info['eeg']['filename'])
     if self._info['avg_group_size'] > 1:
         logging.info("Averaging trials")
         eeg.average_trials(self._info['avg_group_size'], inplace=True)
     if self._info['eeg_derivation'] != 'potential':
         logging.info("Building the %s derivation", self._info['eeg_derivation'])
         if self._info['eeg_derivation'] == "electric_field":
             eeg.get_electric_field(inplace=True)
         elif self._info['eeg_derivation'] == 'laplacian':
             eeg.get_laplacian(inplace=True)
         else:
             raise KeyError("Derivation '%s' is not supported", self._info['eeg_derivation'])
     if eeg.data.ndim == 3:
         eeg.data = eeg.data[:, :, :, np.newaxis]
     labels = eeg.trial_labels
     eeg = eeg.data.reshape(self._info['eeg']['n_channels'], self._info['eeg']['trial_size'], -1, 3).transpose((2, 0, 1, 3))
     idx_train, idx_test = train_test_split(range(len(labels)),
                                            test_size=self._info['test_proportion'],
                                            random_state=self._info['seed'])
     self._info['train_size'] = len(idx_train)
     self._info['test_size'] = len(idx_test)
     batches_train = self._get_batches(max_iter, idx_train, "%s_train" % self._info['subject'], '.hd5')
     self._info['n_train_batches'] = len(batches_train)
     self._info['files_train'] = batches_train.keys()
     created_files = defaultdict(dict)
     logging.info("Creating the batch files")
     for batch_file, trial_indices in batches_train.iteritems():
         encoded_labels = map(lambda x: self.label_encoder.transform(labels[x]), trial_indices)
         if created_files['train'].get(batch_file):
             rec = dd.io.load(batch_file)
             samples = np.r_[rec['samples'], eeg[trial_indices, :, :, :]]
             labs = rec['labels'].append(encoded_labels)
         else:
             samples = eeg[trial_indices, :, :, :]
             labs = encoded_labels
         try:
             dd.io.save(batch_file, {'samples': samples, 'labels': labs})
             if not created_files['train'].get(batch_file):
                 logging.info("Successfully created the training file %s", batch_file)
             created_files['train'][batch_file] = True
         except Exception as e:
             logging.error("Failed to create the training file %s: %s", batch_file, e)
             sys.exit(1)
     test_file = os.path.join(self._info['outdir'], "%s_test.hd5" % self._info['subject'])
     self._info['n_test_batches'] = 1
     self._info['files_test'] = [test_file]
     created_files['test'][test_file] = True
     try:
         dd.io.save(test_file, {'samples': eeg[idx_test, :, :, :],
                                'labels': [list(self.label_encoder.transform(x)) for x in labels[idx_test]]})
         logging.error("Successfully created the test file %s", test_file)
     except Exception as e:
         logging.error("Failed to create the test file %s: %s", test_file, e)
         sys.exit(1)
     logging.info("Finished to create batch files")
     doc = pd.Series(self._info).to_dict()
     data_saver = DataSaver()
     try:
         doc_id = data_saver.save(settings.MONGO_DNN_COLLECTION, doc=doc)
         logging.info("Successfully created the new document %s in the DB", doc_id)
     except Exception as e:
         logging.error("Failed to create a new document in the DB: %s", e)
     return self
def main(args):
    OUTPUT = args.output

    print("Running Android Pre/Post test.\n")
    print("Make sure you have no extra apps running in the background.")
    print("Make sure that there is a wakelock app running"
          "(if going passed 30 minutes of testing).")
    print("Charging is disabled before the test starts. It is")
    print("enabled automatically when we reach the end of the test.")

    _ = input("Press enter when ready...")
    ds = DataSaver(OUTPUT)
    ds.start()

    print("Getting Phone Model...")
    model = get_phone_model()
    print("Is the model %s correct?" % model.model)
    input("Press Enter to confirm...")

    print("Disabling charging...")
    model.disable_charging()
    input("Is it disabled?")

    input("When the test is ready, start the recording by pressing enter...")

    print("Waiting for a percentage drop...")
    #wait_for_drop()
    print("Drop detected, starting test")
    print("Start time: {}".format(datetime.datetime.utcnow()))

    info = parse_battery_info(get_battery_info())
    info["timestamp"] = time.time()
    starttime = info["timestamp"]
    ds.add(info, "batterydata")

    print("Starting values:")
    for k, v in info.items():
        print("{}: {}".format(k, v))

    currtime = 0
    testtime_seconds = TESTTIME * 60
    while currtime - starttime < testtime_seconds:
        time.sleep(5)
        currtime = time.time()
        write_same_line("Elapsed time (seconds): {}".format(
            str(currtime - starttime)))
    finish_same_line()

    info = parse_battery_info(get_battery_info())
    info["timestamp"] = time.time()
    ds.add(info, "batterydata")

    print("End time: {}".format(datetime.datetime.utcnow()))
    print("Final values:")
    for k, v in info.items():
        print("{}: {}".format(k, v))

    print("Enabling charging...")
    model.enable_charging()

    print("Stopping data saver...")
    ds.stop_running()
    print("Done.")
Exemplo n.º 9
0
def main(args):
    OUTPUT = args.output

    print("Running OS baseline (percent-split) test.\n")
    print("Make sure you have no apps running in the background.")
    print("Make sure that there is a wakelock app running.")
    print("Charging is disabled and enabled periodically throughout "
          "the tests to gather {} trials for {} percentage ranges.".format(
              str(TRIALS), str(len(PERCENT_INTERVALS))))

    _ = input("Press enter when ready...")
    ds = DataSaver(OUTPUT)
    ds.start()

    print("Getting Phone Model...")
    model = get_phone_model()
    print("Is the model %s correct?" % model.model)
    input("Press Enter to confirm...")

    print("Disabling charging...")
    model.disable_charging()
    input("Is it disabled?")

    for startpercent, endpercent in PERCENT_INTERVALS:
        print("\nOn percent interval: {} to {}".format(startpercent,
                                                       endpercent))
        trialtimes = []
        for trialnum in range(TRIALS):
            print("\nRunning trial {}, current times are {}".format(
                trialnum, str(trialtimes)))
            print("Start time: {}".format(datetime.datetime.utcnow()))
            info = parse_battery_info(get_battery_info())
            if int(info["level"]) <= startpercent:
                charge_battery(startpercent, model=model)
            elif int(info["level"]) > startpercent:
                discharge_battery(startpercent, model=model)

            dname = "pc_breakdown_{}-{}-{}".format(startpercent, endpercent,
                                                   trialnum)
            outputdir = os.path.join(ds.output, dname)
            os.mkdir(outputdir)

            starttime = time.time()

            try:
                level = 1000
                prevcharge = 0
                prevlevel = 0
                prevtemp = 0
                while level > endpercent:  # end percent is inclusive
                    start = time.time()

                    info = parse_battery_info(get_battery_info())
                    info["timestamp"] = time.time()
                    ds.add(info, os.path.join(dname, "batterydata"))
                    level = int(info["level"])

                    if (prevcharge != info["Charge counter"]
                            or prevlevel != level
                            or prevtemp != info["temperature"]):
                        finish_same_line()
                    write_same_line(
                        "{} | Current capacity: {}%, {}, Temp: {}".format(
                            datetime.datetime.utcnow(),
                            str(level),
                            info["Charge counter"],
                            info["temperature"],
                        ))

                    prevlevel = level
                    prevcharge = info["Charge counter"]
                    prevtemp = info["temperature"]

                    end = time.time()
                    telapsed = end - start

                    if telapsed < RESOLUTION:
                        time.sleep(RESOLUTION - telapsed)
            except Exception as e:
                model.enable_charging()
                raise

            endtime = time.time()
            trialtimes.append(endtime - starttime)

            finish_same_line()

        print("Trial times for {} to {}: {}".format(startpercent, endpercent,
                                                    str(trialtimes)))

        ds.add(
            {"trial-times": trialtimes},
            "ttimes_pc_breakdown_{}-{}".format(startpercent, endpercent),
        )

    print("Enabling charging...")
    model.enable_charging()

    print("Stopping data saver...")
    ds.stop_running()
    print("Done.")