Переработал просто отметки качеств в рейтинг

This commit is contained in:
Dhaverd 2026-07-21 14:47:19 +08:00
parent ab8071da07
commit 9aeea7f22c
5 changed files with 142 additions and 23 deletions

View File

@ -0,0 +1,45 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up (queryInterface, Sequelize) {
const tableName = 'BlacklistReports'; // Убедитесь, что имя таблицы совпадает
const columns = ['toxic', 'cheater', 'afk', 'useless', 'griefer', 'smurf'];
for (const column of columns) {
// 1. Сначала конвертируем данные внутри колонки через SQL-запрос.
// В MySQL true — это 1, а false — это 0.
await queryInterface.sequelize.query(`
UPDATE \`${tableName}\`
SET \`${column}\` = CASE WHEN \`${column}\` = 1 THEN 10 ELSE 0 END
`);
// 2. Теперь безопасно меняем тип самой колонки на TINYINT
await queryInterface.changeColumn(tableName, column, {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 0
});
}
},
async down (queryInterface, Sequelize) {
const tableName = 'BlacklistReports';
const columns = ['toxic', 'cheater', 'afk', 'useless', 'griefer', 'smurf'];
for (const column of columns) {
// Откат: если оценка меньше 5, возвращаем 1 (true), иначе 0 (false)
await queryInterface.sequelize.query(`
UPDATE \`${tableName}\`
SET \`${column}\` = CASE WHEN \`${column}\` < 5 THEN 1 ELSE 0 END
`);
// Возвращаем тип BOOLEAN
await queryInterface.changeColumn(tableName, column, {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false
});
}
}
};

View File

@ -78,7 +78,7 @@ export class BlacklistService {
const result: BlacklistItemList = {};
for (const record of records) {
if (result[record.steam_link]) {
const item: BlacklistItem = result[record.steam_link];
const item: BlacklistItem = result[record.steam_link].blacklistItem;
if (record.steam_nickname !== null) {
item.nicknames.push(record.steam_nickname);
}
@ -89,7 +89,10 @@ export class BlacklistService {
item.useless += Number(record.useless);
item.griefer += Number(record.griefer);
item.smurf += Number(record.smurf);
result[record.steam_link] = item;
result[record.steam_link] = {
blacklistItem: item,
reportCount: result[record.steam_link].reportCount + 1,
};
} else {
const item: BlacklistItem = {
link: record.steam_link,
@ -106,9 +109,41 @@ export class BlacklistService {
item.nicknames.push(record.steam_nickname);
}
item.comments.push(record.comment);
result[record.steam_link] = item;
result[record.steam_link] = {
blacklistItem: item,
reportCount: 1,
};
}
}
for (const res in result) {
result[res].blacklistItem.toxic =
Math.round(
(result[res].blacklistItem.toxic / 2 / result[res].reportCount) * 100,
) / 100;
result[res].blacklistItem.cheater =
Math.round(
(result[res].blacklistItem.cheater / 2 / result[res].reportCount) *
100,
) / 100;
result[res].blacklistItem.afk =
Math.round(
(result[res].blacklistItem.afk / 2 / result[res].reportCount) * 100,
) / 100;
result[res].blacklistItem.useless =
Math.round(
(result[res].blacklistItem.useless / 2 / result[res].reportCount) *
100,
) / 100;
result[res].blacklistItem.griefer =
Math.round(
(result[res].blacklistItem.griefer / 2 / result[res].reportCount) *
100,
) / 100;
result[res].blacklistItem.smurf =
Math.round(
(result[res].blacklistItem.smurf / 2 / result[res].reportCount) * 100,
) / 100;
}
return result;
}

View File

@ -3,10 +3,10 @@ export type BlacklistReportDto = {
steam_link: string;
steam_nickname: string;
comment: string;
toxic: boolean;
cheater: boolean;
afk: boolean;
useless: boolean;
griefer: boolean;
smurf: boolean;
toxic: number;
cheater: number;
afk: number;
useless: number;
griefer: number;
smurf: number;
};

View File

@ -1,4 +1,4 @@
import { Column, DataType, Model, Table } from 'sequelize-typescript';
import { Column, DataType, Max, Min, Model, Table } from 'sequelize-typescript';
@Table
export class BlacklistReport extends Model {
@ -11,23 +11,59 @@ export class BlacklistReport extends Model {
@Column
declare comment: string;
@Column({ defaultValue: false })
declare toxic: boolean;
@Min(0)
@Max(10)
@Column({
type: DataType.TINYINT,
allowNull: false,
defaultValue: false,
})
declare toxic: number;
@Column({ defaultValue: false })
declare cheater: boolean;
@Min(0)
@Max(10)
@Column({
type: DataType.TINYINT,
allowNull: false,
defaultValue: false,
})
declare cheater: number;
@Column({ defaultValue: false })
declare afk: boolean;
@Min(0)
@Max(10)
@Column({
type: DataType.TINYINT,
allowNull: false,
defaultValue: false,
})
declare afk: number;
@Column({ defaultValue: false })
declare useless: boolean;
@Min(0)
@Max(10)
@Column({
type: DataType.TINYINT,
allowNull: false,
defaultValue: false,
})
declare useless: number;
@Column({ defaultValue: false })
declare griefer: boolean;
@Min(0)
@Max(10)
@Column({
type: DataType.TINYINT,
allowNull: false,
defaultValue: false,
})
declare griefer: number;
@Column({ defaultValue: false })
declare smurf: boolean;
@Min(0)
@Max(10)
@Column({
type: DataType.TINYINT,
allowNull: false,
defaultValue: false,
})
declare smurf: number;
@Column({
type: DataType.DATE,

View File

@ -1,5 +1,8 @@
import { BlacklistItem } from './blacklistItem';
export type BlacklistItemList = {
[index: string]: BlacklistItem;
[index: string]: {
blacklistItem: BlacklistItem;
reportCount: number;
};
};