Переработал просто отметки качеств в рейтинг
This commit is contained in:
parent
ab8071da07
commit
9aeea7f22c
|
|
@ -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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -78,7 +78,7 @@ export class BlacklistService {
|
||||||
const result: BlacklistItemList = {};
|
const result: BlacklistItemList = {};
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
if (result[record.steam_link]) {
|
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) {
|
if (record.steam_nickname !== null) {
|
||||||
item.nicknames.push(record.steam_nickname);
|
item.nicknames.push(record.steam_nickname);
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +89,10 @@ export class BlacklistService {
|
||||||
item.useless += Number(record.useless);
|
item.useless += Number(record.useless);
|
||||||
item.griefer += Number(record.griefer);
|
item.griefer += Number(record.griefer);
|
||||||
item.smurf += Number(record.smurf);
|
item.smurf += Number(record.smurf);
|
||||||
result[record.steam_link] = item;
|
result[record.steam_link] = {
|
||||||
|
blacklistItem: item,
|
||||||
|
reportCount: result[record.steam_link].reportCount + 1,
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
const item: BlacklistItem = {
|
const item: BlacklistItem = {
|
||||||
link: record.steam_link,
|
link: record.steam_link,
|
||||||
|
|
@ -106,9 +109,41 @@ export class BlacklistService {
|
||||||
item.nicknames.push(record.steam_nickname);
|
item.nicknames.push(record.steam_nickname);
|
||||||
}
|
}
|
||||||
item.comments.push(record.comment);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ export type BlacklistReportDto = {
|
||||||
steam_link: string;
|
steam_link: string;
|
||||||
steam_nickname: string;
|
steam_nickname: string;
|
||||||
comment: string;
|
comment: string;
|
||||||
toxic: boolean;
|
toxic: number;
|
||||||
cheater: boolean;
|
cheater: number;
|
||||||
afk: boolean;
|
afk: number;
|
||||||
useless: boolean;
|
useless: number;
|
||||||
griefer: boolean;
|
griefer: number;
|
||||||
smurf: boolean;
|
smurf: number;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Column, DataType, Model, Table } from 'sequelize-typescript';
|
import { Column, DataType, Max, Min, Model, Table } from 'sequelize-typescript';
|
||||||
|
|
||||||
@Table
|
@Table
|
||||||
export class BlacklistReport extends Model {
|
export class BlacklistReport extends Model {
|
||||||
|
|
@ -11,23 +11,59 @@ export class BlacklistReport extends Model {
|
||||||
@Column
|
@Column
|
||||||
declare comment: string;
|
declare comment: string;
|
||||||
|
|
||||||
@Column({ defaultValue: false })
|
@Min(0)
|
||||||
declare toxic: boolean;
|
@Max(10)
|
||||||
|
@Column({
|
||||||
|
type: DataType.TINYINT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false,
|
||||||
|
})
|
||||||
|
declare toxic: number;
|
||||||
|
|
||||||
@Column({ defaultValue: false })
|
@Min(0)
|
||||||
declare cheater: boolean;
|
@Max(10)
|
||||||
|
@Column({
|
||||||
|
type: DataType.TINYINT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false,
|
||||||
|
})
|
||||||
|
declare cheater: number;
|
||||||
|
|
||||||
@Column({ defaultValue: false })
|
@Min(0)
|
||||||
declare afk: boolean;
|
@Max(10)
|
||||||
|
@Column({
|
||||||
|
type: DataType.TINYINT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false,
|
||||||
|
})
|
||||||
|
declare afk: number;
|
||||||
|
|
||||||
@Column({ defaultValue: false })
|
@Min(0)
|
||||||
declare useless: boolean;
|
@Max(10)
|
||||||
|
@Column({
|
||||||
|
type: DataType.TINYINT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false,
|
||||||
|
})
|
||||||
|
declare useless: number;
|
||||||
|
|
||||||
@Column({ defaultValue: false })
|
@Min(0)
|
||||||
declare griefer: boolean;
|
@Max(10)
|
||||||
|
@Column({
|
||||||
|
type: DataType.TINYINT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false,
|
||||||
|
})
|
||||||
|
declare griefer: number;
|
||||||
|
|
||||||
@Column({ defaultValue: false })
|
@Min(0)
|
||||||
declare smurf: boolean;
|
@Max(10)
|
||||||
|
@Column({
|
||||||
|
type: DataType.TINYINT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false,
|
||||||
|
})
|
||||||
|
declare smurf: number;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: DataType.DATE,
|
type: DataType.DATE,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
import { BlacklistItem } from './blacklistItem';
|
import { BlacklistItem } from './blacklistItem';
|
||||||
|
|
||||||
export type BlacklistItemList = {
|
export type BlacklistItemList = {
|
||||||
[index: string]: BlacklistItem;
|
[index: string]: {
|
||||||
|
blacklistItem: BlacklistItem;
|
||||||
|
reportCount: number;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue