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) {
const delay = (logSize / 190) + 400;
const delay = (logSize / 180) + 400;
this.delay = Math.max(DEFAULT_DELAY, delay);
}

View file

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

View file

@ -4,18 +4,16 @@ import { IDirtyFile } from 'ts/interfaces/FileInfo';
import { getValuesInPercent } from '../../helpers';
export default class FileBuilderLineStat {
static getProps(fileChange: IFileChange, commit: ICommit) {
return {
lines: fileChange.addedLines,
static setProps(file: any, fileChange: IFileChange, commit: ICommit) {
file.lines = fileChange.addedLines;
addedLines: fileChange.addedLines,
removedLines: fileChange.removedLines,
changedLines: fileChange.changedLines,
file.addedLines = fileChange.addedLines;
file.removedLines = fileChange.removedLines;
file.changedLines = fileChange.changedLines;
addedLinesByAuthor: { [commit.author]: fileChange.addedLines },
removedLinesByAuthor: { [commit.author]: fileChange.removedLines },
changedLinesByAuthor: { [commit.author]: fileChange.changedLines },
};
file.addedLinesByAuthor = { [commit.author]: fileChange.addedLines };
file.removedLinesByAuthor = { [commit.author]: fileChange.removedLines };
file.changedLinesByAuthor = { [commit.author]: fileChange.changedLines };
}
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';
export default class FileBuilderTasks {
static getProps(commit: ICommit) {
return {
tasks: new Set([commit.task]),
timestamp: new Set([commit.timestamp]),
totalTasks: 0,
totalDays: 0,
};
static setProps(file: any, commit: ICommit) {
file.tasks = [commit.task];
file.timestamp = [commit.timestamp];
file.totalTasks = 0;
file.totalDays = 0;
}
static updateProps(file: IDirtyFile, commit: ICommit) {
file.tasks.add(commit.task);
file.timestamp.add(commit.timestamp);
file.tasks.push(commit.task);
file.timestamp.push(commit.timestamp);
}
static updateTotal(file: IDirtyFile) {
file.totalTasks = file.tasks.size;
file.totalDays = file.timestamp.size;
file.tasks = Array.from(new Set(file.tasks));
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) {
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) {
this.#updateDirtyFile(file, fileChange, commit);
} else {
@ -38,16 +40,13 @@ export default class FileGripByPaths {
}
#getNewDirtyFile(fileChange: IFileChange, commit: ICommit): any {
const commonProps = FileBuilderCommon.getProps(fileChange, commit);
const statProps = FileBuilderLineStat.getProps(fileChange, commit);
const tasksProps = FileBuilderTasks.getProps(commit);
const newDirtyFile = { name: '', id: fileChange.id };
return {
id: fileChange.id,
...commonProps,
...statProps,
...tasksProps,
};
FileBuilderCommon.setProps(newDirtyFile, fileChange, commit);
FileBuilderLineStat.setProps(newDirtyFile, fileChange, commit);
FileBuilderTasks.setProps(newDirtyFile, commit);
return newDirtyFile;
}
#updateDirtyFile(file: any, fileChange: IFileChange, commit: ICommit) {
@ -65,16 +64,16 @@ export default class FileGripByPaths {
#removeFile(file: any) {
file.action = 'D';
const oldFile = this.refFileIds.get(file.id) as IDirtyFile;
oldFile.action = 'D';
this.refRemovedFileIds.set(file.id, oldFile);
// const oldFile = this.refFileIds.get(file.id) as IDirtyFile;
// oldFile.action = 'D';
this.refRemovedFileIds.set(file.id, file);
this.refFileIds.delete(file.id);
}
updateTotalInfo(callback?: Function) {
this.list = Array.from(this.refFileIds.values());
this.list.forEach((temp: any) => {
const file = temp;
updateTotalInfo(callback: Function) {
const list = Array.from(this.refFileIds.values());
for (let i = 0, l = list.length; i < l; i++) {
const file = list[i];
FileBuilderCommon.updateTotal(file);
FileBuilderLineStat.updateTotal(file);
@ -95,9 +94,8 @@ export default class FileGripByPaths {
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';
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 {
id: Math.random(),
name: name || '', // @ts-ignore
@ -19,10 +11,10 @@ function getFolder(name?: string, path?: string[], file?: IDirtyFile): IFolder {
pathString: `${(path || []).join('/')}/${name || ''}`,
content: new Map(),
tasks: tasks as Set<string>,
timestamp: timestamp as Set<string>,
totalTasks: tasks.size,
totalDays: timestamp.size,
tasks: file?.tasks || [],
timestamp: file?.timestamp || [],
totalTasks: 0,
totalDays: 0,
lines: file?.lines || 0,
@ -61,11 +53,13 @@ function updateFolder(folder: any, file: IDirtyFile) {
folder.removedLines += file.removedLines || 0;
folder.changedLines += file.changedLines || 0;
// TODO: bad performance
folder.tasks = new Set([...folder.tasks, ...file.tasks]);
folder.timestamp = new Set([...folder.timestamp, ...file.timestamp]);
folder.totalTasks = folder.tasks.size;
folder.totalDays = folder.timestamp.size;
// for performance
for (let i = 0, l = file.tasks.length; i < l; i++) {
folder.tasks.push(file.tasks[i]);
}
for (let i = 0, l = file.timestamp.length; i < l; i++) {
folder.timestamp.push(file.timestamp[i]);
}
updateFolderBy(folder, file, 'addedLinesByAuthor');
updateFolderBy(folder, file, 'removedLinesByAuthor');
@ -87,7 +81,9 @@ export default class FileGripByFolder {
addFile(file: IDirtyFile) {
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);
if (!folder?.content) {
const path = file.path.slice(0, index);
@ -99,12 +95,17 @@ export default class FileGripByFolder {
updateFolder(folder, file);
prev = folder.content;
}
});
}
prev.set(file.name, file);
}
updateTotalInfo() {
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.removedByAuthorInPercent = getValuesInPercent(folder.removedLinesByAuthor, folder.removedLines);
folder.changedByAuthorInPercent = getValuesInPercent(folder.changedLinesByAuthor, folder.changedLines);

View file

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

View file

@ -2,7 +2,7 @@ import { IDirtyFile } from 'ts/interfaces/FileInfo';
import IHashMap from 'ts/interfaces/HashMap';
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']);
@ -45,11 +45,11 @@ export default function getAchievementByFile(fileGrip: any, byAuthor: any) {
const fileRush: IHashMap<number> = {};
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 (IS_CSS[file.extension]) moreStyle.push(getAddedChangedLines(file));
if (IS_TEST[file.extension] || IS_TEST[file.type]) moreTests.push(getAddedChangedLines(file));
if (IS_CI_CD[file.name]) moreDevOps.push(getAddedChangedLines(file));
if (IS_CSS.has[file.extension]) moreStyle.push(getAddedChangedLines(file));
if (IS_TEST.has[file.extension] || IS_TEST.has[file.type]) moreTests.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 || ''] + 1)

View file

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

View file

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