This commit is contained in:
bakhirev 2024-10-18 09:58:45 +03:00
parent ac0e4c797a
commit 8a97106890
11 changed files with 102 additions and 95 deletions

File diff suppressed because one or more lines are too long

View file

@ -28,7 +28,7 @@ class SplashScreenStore {
} }
setDelay(logSize: number) { setDelay(logSize: number) {
const delay = (logSize / 190) + 400; const delay = (logSize / 180) + 400;
this.delay = Math.max(DEFAULT_DELAY, delay); this.delay = Math.max(DEFAULT_DELAY, delay);
} }

View file

@ -1,22 +1,24 @@
import ICommit, { IFileChange } from 'ts/interfaces/Commit'; import ICommit, { IFileChange } from 'ts/interfaces/Commit';
import { IDirtyFile } from 'ts/interfaces/FileInfo'; import { IDirtyFile } from 'ts/interfaces/FileInfo';
function getNameTypeExtension(path?: string) { function getNameTypeExtension(name: string) {
const name = (path || '')?.split('/')?.pop() || ''; const extensionIndex = name.lastIndexOf('.');
const parts = name.split('.') || []; const extension = name.substring(extensionIndex + 1);
const extension = parts[parts.length - 1] || ''; const shortName = name.substring(0, extensionIndex);
const type = parts.length > 2 ? parts[parts.length - 2] : ''; const typeIndex = shortName.lastIndexOf('.');
return { name, type, extension }; const type = typeIndex !== -1
? shortName.substring(typeIndex + 1)
: '';
return { type, extension };
} }
export default class FileBuilderCommon { export default class FileBuilderCommon {
static getProps(fileChange: IFileChange, commit: ICommit) { static setProps(file: any, fileChange: IFileChange, commit: ICommit) {
return { file.name = '';
path: fileChange.path, file.path = fileChange.path;
action: fileChange.action, file.action = fileChange.action;
firstCommit: commit, file.firstCommit = commit;
lastCommit: commit, file.lastCommit = commit;
};
} }
static updateProps(file: IDirtyFile, fileChange: IFileChange, commit: ICommit) { static updateProps(file: IDirtyFile, fileChange: IFileChange, commit: ICommit) {
@ -26,15 +28,15 @@ export default class FileBuilderCommon {
static updateTotal(file: IDirtyFile) { static updateTotal(file: IDirtyFile) {
if (Array.isArray(file?.path)) return; if (Array.isArray(file?.path)) return;
// @ts-ignore
const { name, type, extension } = getNameTypeExtension(file?.path);
file.name = name;
file.type = type;
file.extension = extension;
// @ts-ignore // @ts-ignore
const parts = file.path.split('/'); const parts = file.path.split('/');
parts.pop(); const name = parts.pop() || '';
const typeExtension = getNameTypeExtension(name);
file.name = name;
file.type = typeExtension.type;
file.extension = typeExtension.extension;
file.pathString = file.path; file.pathString = file.path;
file.path = parts; file.path = parts;
} }

View file

@ -4,18 +4,16 @@ import { IDirtyFile } from 'ts/interfaces/FileInfo';
import { getValuesInPercent } from '../../helpers'; import { getValuesInPercent } from '../../helpers';
export default class FileBuilderLineStat { export default class FileBuilderLineStat {
static getProps(fileChange: IFileChange, commit: ICommit) { static setProps(file: any, fileChange: IFileChange, commit: ICommit) {
return { file.lines = fileChange.addedLines;
lines: fileChange.addedLines,
addedLines: fileChange.addedLines, file.addedLines = fileChange.addedLines;
removedLines: fileChange.removedLines, file.removedLines = fileChange.removedLines;
changedLines: fileChange.changedLines, file.changedLines = fileChange.changedLines;
addedLinesByAuthor: { [commit.author]: fileChange.addedLines }, file.addedLinesByAuthor = { [commit.author]: fileChange.addedLines };
removedLinesByAuthor: { [commit.author]: fileChange.removedLines }, file.removedLinesByAuthor = { [commit.author]: fileChange.removedLines };
changedLinesByAuthor: { [commit.author]: fileChange.changedLines }, file.changedLinesByAuthor = { [commit.author]: fileChange.changedLines };
};
} }
static updateProps(file: IDirtyFile, fileChange: IFileChange, commit: ICommit) { static updateProps(file: IDirtyFile, fileChange: IFileChange, commit: ICommit) {

View file

@ -2,22 +2,22 @@ import ICommit from 'ts/interfaces/Commit';
import { IDirtyFile } from 'ts/interfaces/FileInfo'; import { IDirtyFile } from 'ts/interfaces/FileInfo';
export default class FileBuilderTasks { export default class FileBuilderTasks {
static getProps(commit: ICommit) { static setProps(file: any, commit: ICommit) {
return { file.tasks = [commit.task];
tasks: new Set([commit.task]), file.timestamp = [commit.timestamp];
timestamp: new Set([commit.timestamp]), file.totalTasks = 0;
totalTasks: 0, file.totalDays = 0;
totalDays: 0,
};
} }
static updateProps(file: IDirtyFile, commit: ICommit) { static updateProps(file: IDirtyFile, commit: ICommit) {
file.tasks.add(commit.task); file.tasks.push(commit.task);
file.timestamp.add(commit.timestamp); file.timestamp.push(commit.timestamp);
} }
static updateTotal(file: IDirtyFile) { static updateTotal(file: IDirtyFile) {
file.totalTasks = file.tasks.size; file.tasks = Array.from(new Set(file.tasks));
file.totalDays = file.timestamp.size; file.timestamp = Array.from(new Set(file.timestamp));
file.totalTasks = file.tasks.length;
file.totalDays = file.timestamp.length;
} }
} }

View file

@ -24,7 +24,9 @@ export default class FileGripByPaths {
} }
addCommit(fileChange: IFileChange, commit: ICommit) { addCommit(fileChange: IFileChange, commit: ICommit) {
let file = this.refFileIds.get(fileChange.id) || this.refFileIds.get(fileChange.newId); // TODO: performance
let file = this.refFileIds.get(fileChange.id);
if (!file) file = this.refFileIds.get(fileChange.newId);
if (file) { if (file) {
this.#updateDirtyFile(file, fileChange, commit); this.#updateDirtyFile(file, fileChange, commit);
} else { } else {
@ -38,16 +40,13 @@ export default class FileGripByPaths {
} }
#getNewDirtyFile(fileChange: IFileChange, commit: ICommit): any { #getNewDirtyFile(fileChange: IFileChange, commit: ICommit): any {
const commonProps = FileBuilderCommon.getProps(fileChange, commit); const newDirtyFile = { name: '', id: fileChange.id };
const statProps = FileBuilderLineStat.getProps(fileChange, commit);
const tasksProps = FileBuilderTasks.getProps(commit);
return { FileBuilderCommon.setProps(newDirtyFile, fileChange, commit);
id: fileChange.id, FileBuilderLineStat.setProps(newDirtyFile, fileChange, commit);
...commonProps, FileBuilderTasks.setProps(newDirtyFile, commit);
...statProps,
...tasksProps, return newDirtyFile;
};
} }
#updateDirtyFile(file: any, fileChange: IFileChange, commit: ICommit) { #updateDirtyFile(file: any, fileChange: IFileChange, commit: ICommit) {
@ -65,16 +64,16 @@ export default class FileGripByPaths {
#removeFile(file: any) { #removeFile(file: any) {
file.action = 'D'; file.action = 'D';
const oldFile = this.refFileIds.get(file.id) as IDirtyFile; // const oldFile = this.refFileIds.get(file.id) as IDirtyFile;
oldFile.action = 'D'; // oldFile.action = 'D';
this.refRemovedFileIds.set(file.id, oldFile); this.refRemovedFileIds.set(file.id, file);
this.refFileIds.delete(file.id); this.refFileIds.delete(file.id);
} }
updateTotalInfo(callback?: Function) { updateTotalInfo(callback: Function) {
this.list = Array.from(this.refFileIds.values()); const list = Array.from(this.refFileIds.values());
this.list.forEach((temp: any) => { for (let i = 0, l = list.length; i < l; i++) {
const file = temp; const file = list[i];
FileBuilderCommon.updateTotal(file); FileBuilderCommon.updateTotal(file);
FileBuilderLineStat.updateTotal(file); FileBuilderLineStat.updateTotal(file);
@ -95,9 +94,8 @@ export default class FileGripByPaths {
this.#removeFile(file); this.#removeFile(file);
} }
if (callback) {
callback(file); callback(file);
} }
}); this.list = list;
} }
} }

View file

@ -4,14 +4,6 @@ import IHashMap from 'ts/interfaces/HashMap';
import { getValuesInPercent } from '../helpers'; import { getValuesInPercent } from '../helpers';
function getFolder(name?: string, path?: string[], file?: IDirtyFile): IFolder { function getFolder(name?: string, path?: string[], file?: IDirtyFile): IFolder {
const tasks = file?.tasks
? new Set(file.tasks)
: new Set();
const timestamp = file?.timestamp
? new Set(file.timestamp) as Set<string>
: new Set();
return { return {
id: Math.random(), id: Math.random(),
name: name || '', // @ts-ignore name: name || '', // @ts-ignore
@ -19,10 +11,10 @@ function getFolder(name?: string, path?: string[], file?: IDirtyFile): IFolder {
pathString: `${(path || []).join('/')}/${name || ''}`, pathString: `${(path || []).join('/')}/${name || ''}`,
content: new Map(), content: new Map(),
tasks: tasks as Set<string>, tasks: file?.tasks || [],
timestamp: timestamp as Set<string>, timestamp: file?.timestamp || [],
totalTasks: tasks.size, totalTasks: 0,
totalDays: timestamp.size, totalDays: 0,
lines: file?.lines || 0, lines: file?.lines || 0,
@ -61,11 +53,13 @@ function updateFolder(folder: any, file: IDirtyFile) {
folder.removedLines += file.removedLines || 0; folder.removedLines += file.removedLines || 0;
folder.changedLines += file.changedLines || 0; folder.changedLines += file.changedLines || 0;
// TODO: bad performance // for performance
folder.tasks = new Set([...folder.tasks, ...file.tasks]); for (let i = 0, l = file.tasks.length; i < l; i++) {
folder.timestamp = new Set([...folder.timestamp, ...file.timestamp]); folder.tasks.push(file.tasks[i]);
folder.totalTasks = folder.tasks.size; }
folder.totalDays = folder.timestamp.size; for (let i = 0, l = file.timestamp.length; i < l; i++) {
folder.timestamp.push(file.timestamp[i]);
}
updateFolderBy(folder, file, 'addedLinesByAuthor'); updateFolderBy(folder, file, 'addedLinesByAuthor');
updateFolderBy(folder, file, 'removedLinesByAuthor'); updateFolderBy(folder, file, 'removedLinesByAuthor');
@ -87,7 +81,9 @@ export default class FileGripByFolder {
addFile(file: IDirtyFile) { addFile(file: IDirtyFile) {
let prev: any = this.tree.content; let prev: any = this.tree.content;
file.path.forEach((folderName: any, index: number) => { // for performance
for (let index = 0, l = file.path.length; index < l; index++) {
const folderName = file.path[index];
const folder = prev.get(folderName); const folder = prev.get(folderName);
if (!folder?.content) { if (!folder?.content) {
const path = file.path.slice(0, index); const path = file.path.slice(0, index);
@ -99,12 +95,17 @@ export default class FileGripByFolder {
updateFolder(folder, file); updateFolder(folder, file);
prev = folder.content; prev = folder.content;
} }
}); }
prev.set(file.name, file); prev.set(file.name, file);
} }
updateTotalInfo() { updateTotalInfo() {
this.folders.forEach((folder: IFolder) => { this.folders.forEach((folder: IFolder) => {
folder.tasks = Array.from(new Set(folder.tasks));
folder.timestamp = Array.from(new Set(folder.timestamp));
folder.totalTasks = folder.tasks.length;
folder.totalDays = folder.timestamp.length;
folder.addedByAuthorInPercent = getValuesInPercent(folder.addedLinesByAuthor, folder.addedLines); folder.addedByAuthorInPercent = getValuesInPercent(folder.addedLinesByAuthor, folder.addedLines);
folder.removedByAuthorInPercent = getValuesInPercent(folder.removedLinesByAuthor, folder.removedLines); folder.removedByAuthorInPercent = getValuesInPercent(folder.removedLinesByAuthor, folder.removedLines);
folder.changedByAuthorInPercent = getValuesInPercent(folder.changedLinesByAuthor, folder.changedLines); folder.changedByAuthorInPercent = getValuesInPercent(folder.changedLinesByAuthor, folder.changedLines);

View file

@ -1,9 +1,10 @@
import { IFileChange } from 'ts/interfaces/Commit'; import { IFileChange } from 'ts/interfaces/Commit';
function getFilePath(path: string): string[] { function getFilePath(path: string): string[] {
const formattedPath = path // 0 0 "UI tests/\\320\\224\\320\\276\\320\\272\\321\\203\\320/my_lock.lock"
.replace(/"/gm, '') const formattedPath = path[path.length - 1] === '"'
.replace(/\/\//gm, '/'); ? path.replace(/"/gm, '').replace(/\/\//gm, '/')
: path;
if (formattedPath.indexOf('{') === -1) return [formattedPath]; if (formattedPath.indexOf('{') === -1) return [formattedPath];

View file

@ -2,7 +2,7 @@ import { IDirtyFile } from 'ts/interfaces/FileInfo';
import IHashMap from 'ts/interfaces/HashMap'; import IHashMap from 'ts/interfaces/HashMap';
function getHashMap(list: string[]) { function getHashMap(list: string[]) {
return Object.fromEntries(list.map((code: string) => [code, true])); return new Map(list.map((code: string) => [code, true]));
} }
const IS_LINT_HINT = getHashMap(['.eslintrc', '.stylelintrc.json']); const IS_LINT_HINT = getHashMap(['.eslintrc', '.stylelintrc.json']);
@ -45,11 +45,11 @@ export default function getAchievementByFile(fileGrip: any, byAuthor: any) {
const fileRush: IHashMap<number> = {}; const fileRush: IHashMap<number> = {};
fileGrip.files.list.forEach((file: IDirtyFile) => { fileGrip.files.list.forEach((file: IDirtyFile) => {
if (IS_LINT_HINT[file.name]) moreLintHint.push(getAddedChangedLines(file)); if (IS_LINT_HINT.has[file.name]) moreLintHint.push(getAddedChangedLines(file));
if (file.extension === 'md') moreReadMe.push(getAddedChangedLines(file)); if (file.extension === 'md') moreReadMe.push(getAddedChangedLines(file));
if (IS_CSS[file.extension]) moreStyle.push(getAddedChangedLines(file)); if (IS_CSS.has[file.extension]) moreStyle.push(getAddedChangedLines(file));
if (IS_TEST[file.extension] || IS_TEST[file.type]) moreTests.push(getAddedChangedLines(file)); if (IS_TEST.has[file.extension] || IS_TEST.has[file.type]) moreTests.push(getAddedChangedLines(file));
if (IS_CI_CD[file.name]) moreDevOps.push(getAddedChangedLines(file)); if (IS_CI_CD.has[file.name]) moreDevOps.push(getAddedChangedLines(file));
fileRush[file.firstCommit?.author || ''] = fileRush[file.firstCommit?.author || ''] fileRush[file.firstCommit?.author || ''] = fileRush[file.firstCommit?.author || '']
? (fileRush[file.firstCommit?.author || ''] + 1) ? (fileRush[file.firstCommit?.author || ''] + 1)

View file

@ -2,8 +2,8 @@ import ICommit, { ISystemCommit } from './Commit';
import IHashMap, { HashMap } from './HashMap'; import IHashMap, { HashMap } from './HashMap';
interface IFileStat { interface IFileStat {
tasks: Set<string>; // ['JIRA-123', 'JIRA-444'] tasks: string[]; // ['JIRA-123', 'JIRA-444']
timestamp: Set<string>; // ['2021-02-09', '2021-03-09', '2021-04-09'] timestamp: string[]; // ['2021-02-09', '2021-03-09', '2021-04-09']
totalTasks: number; // 2 totalTasks: number; // 2
totalDays: number; // 3 totalDays: number; // 3

View file

@ -67,6 +67,13 @@ class DataGripStore {
commits.sort((a, b) => a.milliseconds - b.milliseconds); commits.sort((a, b) => a.milliseconds - b.milliseconds);
commits.forEach((commit: ICommit | ISystemCommit) => { commits.forEach((commit: ICommit | ISystemCommit) => {
dataGrip.addCommit(commit); dataGrip.addCommit(commit);
});
setTimeout(() => this.processingFileGrouping(commits), PROCESSING_DELAY);
}
processingFileGrouping(commits: (ICommit | ISystemCommit)[]) {
commits.forEach((commit: ICommit | ISystemCommit) => {
fileGrip.addCommit(commit); fileGrip.addCommit(commit);
}); });