コード例 #1
0
async def read_warning_log_data_by_id(data_id: int,
                                      mp_id: int,
                                      fault_mode: FaultRule,
                                      conn: Database = Depends(get_db)):
    """
    Get warning log data by ID and fault pattern.
    """
    data = await get_data_by_id(
        conn=conn,
        mp_id=mp_id,
        orm_model=VibData,
        require_mp_type=0,
        data_id=data_id,
    )
    if not data:
        raise HTTPException(status_code=400, detail="Item not found")
    signal = VibrationSignal(data=np.fromstring(data["ima"], dtype=np.float32),
                             fs=10000,
                             type=2)

    if (fault_mode == FaultRule.ub or fault_mode == FaultRule.ma
            or fault_mode == FaultRule.al or fault_mode == FaultRule.bl
            or fault_mode == FaultRule.rb):
        signal = signal.to_velocity(detrend_type="poly")
        signal.compute_spectrum()
        return {"spec": signal.spec, "freq": signal.freq}
    if fault_mode == FaultRule.bw:
        signal = signal.to_filted_signal(filter_type="highpass",
                                         co_frequency=2 * 1000 /
                                         10000).to_envelope()
        signal.compute_spectrum()
        return {"spec": signal.spec, "freq": signal.freq}
    if fault_mode == FaultRule.sg:
        signal.compute_spectrum()
        return {"spec": signal.spec, "freq": signal.freq}
コード例 #2
0
def acceleration_to_velocity(data: str) -> dict:
    acc = VibrationSignal(data=binary_deserializer(data), fs=10000)
    vel = acc.to_velocity()
    acc.compute_spectrum(compute_axis=False)
    vel.compute_spectrum(compute_axis=False)
    return {
        "vel": vel.data,
        "acc": acc.data,
        "acc_spec": acc.spec,
        "vel_spec": vel.spec,
    }