Example #1
0
async def set_memory_preferences(request: Request, session_uuid: str) -> Any:
    preferences_key = MemoryPreferencesIndex.get(session_uuid)

    if not preferences_key:
        return {}

    mp = preferences_key.load()
    json = await request.json()
    mp.update_preferences(json)

    logger.debug(f'update memory preferences: {mp.key}')

    return {'errors': mp.errors}
Example #2
0
async def set_hyper_params_preferences(request: Request, run_uuid: str) -> Any:
    preferences_key = HyperParamsPreferencesIndex.get(run_uuid)

    if not preferences_key:
        return {}

    hpp = preferences_key.load()
    json = await request.json()
    hpp.update_preferences(json)

    logger.debug(f'update hyper_params preferences: {hpp.key}')

    return {'errors': hpp.errors}
Example #3
0
async def set_gpu_preferences(request: Request, session_uuid: str) -> Any:
    preferences_key = GPUPreferencesIndex.get(session_uuid)

    if not preferences_key:
        return {}

    gp = preferences_key.load()
    json = await request.json()
    gp.update_sub_series_preferences(json)

    logger.debug(f'update gpu preferences: {gp.key}')

    return {'errors': gp.errors}
Example #4
0
async def set_params_preferences(request: Request, run_uuid: str) -> Any:
    preferences_key = ParametersPreferencesIndex.get(run_uuid)

    if not preferences_key:
        return {}

    pp = preferences_key.load()
    json = await request.json()
    pp.update_preferences(json)

    logger.debug(f'update parameters preferences: {pp.key}')

    return {'errors': pp.errors}
Example #5
0
async def set_modules_preferences(request: Request, run_uuid: str) -> Any:
    preferences_key = OutputsPreferencesIndex.get(run_uuid)

    if not preferences_key:
        return {}

    op = preferences_key.load()
    json = await request.json()
    op.update_preferences(json)

    logger.debug(f'update outputs preferences: {op.key}')

    return {'errors': op.errors}
Example #6
0
async def set_cpu_preferences(request: Request, session_uuid: str) -> Any:
    preferences_key = CPUPreferencesIndex.get(session_uuid)

    if not preferences_key:
        return {}

    cp = preferences_key.load()
    json = await request.json()
    cp.update_preferences(json)

    logger.debug(f'update cpu preferences: {cp.key}')

    return {'errors': cp.errors}
Example #7
0
async def set_disk_preferences(request: Request, session_uuid: str) -> Any:
    preferences_key = DiskPreferencesIndex.get(session_uuid)

    if not preferences_key:
        return {}

    dp = preferences_key.load()
    json = await request.json()
    dp.update_preferences(json)

    logger.debug(f'update disk preferences: {dp.key}')

    return {'errors': dp.errors}
Example #8
0
async def set_grads_preferences(request: Request, run_uuid: str) -> Any:
    preferences_key = GradientsPreferencesIndex.get(run_uuid)

    if not preferences_key:
        return {}

    gp = preferences_key.load()
    json = await request.json()
    gp.update_preferences(json)

    logger.debug(f'update gradients preferences: {gp.key}')

    return {'errors': gp.errors}
Example #9
0
async def set_network_preferences(request: Request, session_uuid: str) -> Any:
    preferences_key = NetworkPreferencesIndex.get(session_uuid)

    if not preferences_key:
        return {}

    np = preferences_key.load()
    json = await request.json()
    np.update_preferences(json)

    logger.debug(f'update network preferences: {np.key}')

    return {'errors': np.errors}
Example #10
0
async def set_battery_preferences(request: Request, session_uuid: str) -> Any:
    preferences_key = BatteryPreferencesIndex.get(session_uuid)

    if not preferences_key:
        return {}

    bp = preferences_key.load()
    json = await request.json()
    bp.update_preferences(json)

    logger.debug(f'update battery_key preferences: {bp.key}')

    return {'errors': bp.errors}
Example #11
0
async def set_comparison_preferences(request: Request, run_uuid: str) -> Any:
    preferences_key = ComparisonPreferencesIndex.get(run_uuid)

    if not preferences_key:
        cp = ComparisonPreferencesModel()
        ComparisonPreferencesIndex.set(run_uuid, cp.key)
    else:
        cp = preferences_key.load()

    json = await request.json()
    cp.update_preferences(json)

    logger.debug(f'update comparison preferences: {cp.key}')

    return {'errors': cp.errors}
Example #12
0
async def log_process_time(request: Request, call_next):
    """
    Save time before each request
    TODO: Track time and content size in tracker. No need of logs"""
    timestamp = strftime('[%Y-%b-%d %H:%M]')
    request_start_time = time.time()
    logger.debug(f'time: {timestamp} uri: {request.url}')

    response: Response = await call_next(request)
    """Calculate and log execution time"""
    request_time = time.time() - request_start_time

    logger.info(
        f'PERF time: {request_time * 1000:.2f}ms uri: {request.url} method:{request.method}'
    )

    # TODO check this; otherwise network.ts:43 Refused to get unsafe header "Authorization"
    response.headers['Access-Control-Expose-Headers'] = 'Authorization'
    # response.headers['Access-Control-Max-Age'] = str(60 * 24)

    return response