示例#1
0
def run_all():
    process_manager = app.config['PROCESS_MANAGER']
    device_manager = app.config['DEVICE_MANAGER']
    body = request.json

    devices = Device.from_json_request(body, many=True)
    results = []
    for device in devices:
        address = device.address
        device = _run(address, device, device_manager, process_manager)
        results.append(device)
    # save location mapping information
    location_mapping_df = Device.to_location_mapping_csv(*devices, pid=app.config['SELECTED_SUBJECT'])
    if app.config['SELECTED_SUBJECT'] is None:
        logging_folder = False
    else:
        logging_folder = os.path.abspath(os.path.join('data-logging', 'DerivedCrossParticipants'))
    os.makedirs(logging_folder, exist_ok=True)
    logging.info('Create logging folder: ' + logging_folder)
    output_file = os.path.join(logging_folder,'location_mapping.csv')
    if os.path.exists(output_file):
        location_mapping_df.to_csv(output_file, header=False, index=False, mode='a')
    else:
        location_mapping_df.to_csv(output_file, header=True, index=False)
    logging.info('Saved location mapping information')
    response = Device.to_json_responses(*results, time.time())
    return jsonify(response), 200
示例#2
0
def stop_all():
    device_manager = app.config['DEVICE_MANAGER']
    print(request.json)
    devices = Device.from_json_request(request.json, many=True)
    addresses = list(map(lambda d: d.address, devices))
    results = []
    for address in addresses:
        device = _stop(address, device_manager)
        results.append(device)
    response = Device.to_json_responses(*results, time.time())
    return jsonify(response)
示例#3
0
def get_all():
    # get query parameter
    scan = int(request.args.get('scan'))
    device_manager = app.config['DEVICE_MANAGER']
    devices = list(
        map(lambda device_state: device_state['device'], device_manager))
    logging.info(devices)
    if scan == 1:
        scanner = MetaWearScanner()
        addresses = scanner.scan()
        devices += [
            Device(address=address, status='stopped') for address in addresses
        ]
    response = Device.to_json_responses(*devices, timestamp=time.time())
    return jsonify(response), 200