mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Add AQI space daily pollutant stats module and related entities, DTOs, and repositories
This commit is contained in:
@ -55,6 +55,7 @@ import {
|
|||||||
PresenceSensorDailyDeviceEntity,
|
PresenceSensorDailyDeviceEntity,
|
||||||
PresenceSensorDailySpaceEntity,
|
PresenceSensorDailySpaceEntity,
|
||||||
} from '../modules/presence-sensor/entities';
|
} from '../modules/presence-sensor/entities';
|
||||||
|
import { AqiSpaceDailyPollutantStatsEntity } from '../modules/aqi/entities';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forRootAsync({
|
TypeOrmModule.forRootAsync({
|
||||||
@ -115,6 +116,7 @@ import {
|
|||||||
PowerClampMonthlyEntity,
|
PowerClampMonthlyEntity,
|
||||||
PresenceSensorDailyDeviceEntity,
|
PresenceSensorDailyDeviceEntity,
|
||||||
PresenceSensorDailySpaceEntity,
|
PresenceSensorDailySpaceEntity,
|
||||||
|
AqiSpaceDailyPollutantStatsEntity,
|
||||||
],
|
],
|
||||||
namingStrategy: new SnakeNamingStrategy(),
|
namingStrategy: new SnakeNamingStrategy(),
|
||||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||||
|
11
libs/common/src/modules/aqi/aqi.repository.module.ts
Normal file
11
libs/common/src/modules/aqi/aqi.repository.module.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { AqiSpaceDailyPollutantStatsEntity } from './entities/aqi.entity';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [],
|
||||||
|
exports: [],
|
||||||
|
controllers: [],
|
||||||
|
imports: [TypeOrmModule.forFeature([AqiSpaceDailyPollutantStatsEntity])],
|
||||||
|
})
|
||||||
|
export class AqiRepositoryModule {}
|
82
libs/common/src/modules/aqi/dtos/aqi.dto.ts
Normal file
82
libs/common/src/modules/aqi/dtos/aqi.dto.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class AqiSpaceDailyPollutantStatsDto {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public uuid: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsString()
|
||||||
|
spaceUuid: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsString()
|
||||||
|
eventDay: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsNumber()
|
||||||
|
eventHour: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm1Min: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm1Avg: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm1Max: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm10Min: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm10Avg: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm10Max: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm25Min: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm25Avg: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
pm25Max: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
ch2oMin: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
ch2oAvg: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
ch2oMax: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
vocMin: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
vocAvg: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
vocMax: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
co2Min: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
co2Avg: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
co2Max: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
aqiMin: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
aqiAvg: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
aqiMax: number;
|
||||||
|
}
|
1
libs/common/src/modules/aqi/dtos/index.ts
Normal file
1
libs/common/src/modules/aqi/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './aqi.dto';
|
88
libs/common/src/modules/aqi/entities/aqi.entity.ts
Normal file
88
libs/common/src/modules/aqi/entities/aqi.entity.ts
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import { Column, Entity, ManyToOne, Unique } from 'typeorm';
|
||||||
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
|
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||||
|
import { AqiSpaceDailyPollutantStatsDto } from '../dtos';
|
||||||
|
|
||||||
|
@Entity({ name: 'space-daily-pollutant-stats' })
|
||||||
|
@Unique(['spaceUuid', 'eventDay', 'eventHour'])
|
||||||
|
export class AqiSpaceDailyPollutantStatsEntity extends AbstractEntity<AqiSpaceDailyPollutantStatsDto> {
|
||||||
|
@Column({ nullable: false })
|
||||||
|
public spaceUuid: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => SpaceEntity, (space) => space.presenceSensorDaily)
|
||||||
|
space: SpaceEntity;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
public eventDay: string;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
public eventHour: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm1Min: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm1Avg: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm1Max: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm10Min: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm10Avg: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm10Max: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm25Min: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm25Avg: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public pm25Max: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public ch2oMin: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public ch2oAvg: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public ch2oMax: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public vocMin: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public vocAvg: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public vocMax: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public co2Min: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public co2Avg: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public co2Max: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public aqiMin: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public aqiAvg: number;
|
||||||
|
|
||||||
|
@Column('float', { nullable: true })
|
||||||
|
public aqiMax: number;
|
||||||
|
|
||||||
|
constructor(partial: Partial<AqiSpaceDailyPollutantStatsEntity>) {
|
||||||
|
super();
|
||||||
|
Object.assign(this, partial);
|
||||||
|
}
|
||||||
|
}
|
1
libs/common/src/modules/aqi/entities/index.ts
Normal file
1
libs/common/src/modules/aqi/entities/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './aqi.entity';
|
1
libs/common/src/modules/aqi/repositories/index.ts
Normal file
1
libs/common/src/modules/aqi/repositories/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './presence-sensor.repository';
|
@ -0,0 +1,19 @@
|
|||||||
|
import { DataSource, Repository } from 'typeorm';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
PresenceSensorDailyDeviceEntity,
|
||||||
|
PresenceSensorDailySpaceEntity,
|
||||||
|
} from '../entities';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PresenceSensorDailyDeviceRepository extends Repository<PresenceSensorDailyDeviceEntity> {
|
||||||
|
constructor(private dataSource: DataSource) {
|
||||||
|
super(PresenceSensorDailyDeviceEntity, dataSource.createEntityManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Injectable()
|
||||||
|
export class PresenceSensorDailySpaceRepository extends Repository<PresenceSensorDailySpaceEntity> {
|
||||||
|
constructor(private dataSource: DataSource) {
|
||||||
|
super(PresenceSensorDailySpaceEntity, dataSource.createEntityManager());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user