mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
splash chart data
This commit is contained in:
@@ -9,8 +9,10 @@ import { ClientStatisticsEntity } from './client-statistics.entity';
|
||||
export class ClientStatisticsService {
|
||||
|
||||
constructor(
|
||||
|
||||
|
||||
@InjectRepository(ClientStatisticsEntity)
|
||||
private clientStatisticsRepository: Repository<ClientStatisticsEntity>
|
||||
private clientStatisticsRepository: Repository<ClientStatisticsEntity>,
|
||||
) {
|
||||
|
||||
}
|
||||
@@ -30,6 +32,38 @@ export class ClientStatisticsService {
|
||||
.execute();
|
||||
}
|
||||
|
||||
public async getChartDataForSite() {
|
||||
|
||||
|
||||
const query = `
|
||||
WITH result_set AS (
|
||||
SELECT
|
||||
MAX(time) || 'GMT' AS label,
|
||||
(SUM(difficulty) * 4294967296) /
|
||||
((JULIANDAY(MAX(time)) - JULIANDAY(MIN(time))) * 24 * 60 * 60 * 1000000000) AS data
|
||||
FROM
|
||||
client_statistics_entity AS entry
|
||||
WHERE
|
||||
entry.time > datetime("now", "-1 day")
|
||||
GROUP BY
|
||||
strftime('%Y-%m-%d %H', time, 'localtime') || (strftime('%M', time, 'localtime') / 10)
|
||||
ORDER BY
|
||||
time
|
||||
)
|
||||
SELECT *
|
||||
FROM result_set
|
||||
WHERE label <> (SELECT MAX(label) FROM result_set);
|
||||
`;
|
||||
|
||||
const result = await this.clientStatisticsRepository.query(query);
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async getHashRateForAddress(address: string) {
|
||||
|
||||
const query = `
|
||||
|
||||
+23
-5
@@ -1,18 +1,36 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { Controller, Get, Inject } from '@nestjs/common';
|
||||
import { Cache } from 'cache-manager';
|
||||
|
||||
import { ClientStatisticsService } from './ORM/client-statistics/client-statistics.service';
|
||||
import { ClientService } from './ORM/client/client.service';
|
||||
|
||||
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(
|
||||
private clientService: ClientService
|
||||
@Inject(CACHE_MANAGER) private cacheManager: Cache,
|
||||
private clientService: ClientService,
|
||||
private clientStatisticsService: ClientStatisticsService
|
||||
) { }
|
||||
|
||||
@Get('info')
|
||||
public info() {
|
||||
public async info() {
|
||||
|
||||
const CACHE_KEY = 'SITE_HASHRATE_GRAPH';
|
||||
const cachedResult = await this.cacheManager.get(CACHE_KEY);
|
||||
if (cachedResult != null) {
|
||||
return {
|
||||
chartData: cachedResult
|
||||
};
|
||||
}
|
||||
|
||||
const chartData = await this.clientStatisticsService.getChartDataForSite();
|
||||
|
||||
await this.cacheManager.set(CACHE_KEY, chartData, 600)
|
||||
|
||||
return {
|
||||
chartData
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { ScheduleModule } from '@nestjs/schedule';
|
||||
@@ -35,7 +36,9 @@ const ORMModules = [
|
||||
autoLoadEntities: true,
|
||||
logging: false
|
||||
}),
|
||||
CacheModule.register(),
|
||||
ScheduleModule.forRoot(),
|
||||
|
||||
...ORMModules
|
||||
],
|
||||
controllers: [
|
||||
|
||||
@@ -39,7 +39,11 @@ export class DiscordService implements OnModuleInit {
|
||||
this.guildId = this.configService.get('DISCORD_BOT_GUILD_ID');
|
||||
this.channelId = this.configService.get('DISCORD_BOT_CHANNEL_ID')
|
||||
|
||||
if (this.token.length < 1 || this.clientId.length < 1 || this.guildId.length < 1 || this.channelId.length < 1) {
|
||||
if (this.token == null || this.token.length < 1 ||
|
||||
this.clientId == null || this.clientId.length < 1 ||
|
||||
this.guildId == null || this.guildId.length < 1 ||
|
||||
this.channelId == null || this.channelId.length < 1
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export class TelegramService implements OnModuleInit {
|
||||
private readonly telegramSubscriptionsService: TelegramSubscriptionsService
|
||||
) {
|
||||
const token: string | null = this.configService.get('TELEGRAM_BOT_TOKEN');
|
||||
if (token.length < 1) {
|
||||
if (token == null || token.length < 1) {
|
||||
return;
|
||||
}
|
||||
this.bot = new TelegramBot(token, { polling: true });
|
||||
|
||||
Reference in New Issue
Block a user