an qua la ngu
This commit is contained in:
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Program",
|
||||||
|
"runtimeExecutable": "C:\\Users\\AliensVN\\AppData\\Roaming\\fnm\\node-versions\\v20.17.0\\installation\\node.exe",
|
||||||
|
"skipFiles": [
|
||||||
|
"<node_internals>/**"
|
||||||
|
],
|
||||||
|
"program": "${file}",
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/**/*.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
21
src/common/custom_types/schedule.date.type.d.ts
vendored
Normal file
21
src/common/custom_types/schedule.date.type.d.ts
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export type ScheduleDateJSON = {};
|
||||||
|
|
||||||
|
export type ScheduleDate = Date | ScheduleDateJSON;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
[id:startTimeStamp - endTimeStamp, id:startTimeStamp - endTimeStamp, ...]
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
1728206200 - 1728206300
|
||||||
|
1728206400 - 1728206500
|
||||||
|
1728206600 - 1728206700
|
||||||
|
1728206800 - 1728206900
|
||||||
|
1728207000 - 1728207100
|
||||||
|
1728207200 - 1728207300
|
||||||
|
1728207400 - 1728207500
|
||||||
|
1728207600 - 1728207700
|
||||||
|
|
||||||
|
|
||||||
69
src/common/utils/datetime.utils.ts
Normal file
69
src/common/utils/datetime.utils.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
function getOverlapRange(
|
||||||
|
startA: number,
|
||||||
|
endA: number,
|
||||||
|
startB: number,
|
||||||
|
endB: number
|
||||||
|
) {
|
||||||
|
const overlapStart = Math.max(startA, startB);
|
||||||
|
const overlapEnd = Math.min(endA, endB);
|
||||||
|
|
||||||
|
return overlapStart < overlapEnd ? { overlapStart, overlapEnd } : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isOverlap(
|
||||||
|
startA: number,
|
||||||
|
endA: number,
|
||||||
|
startB: number,
|
||||||
|
endB: number
|
||||||
|
) {
|
||||||
|
return getOverlapRange(startA, endA, startB, endB) !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate random time ranges for the schedulers
|
||||||
|
function generateTimeRanges(count: number): { start: number; end: number }[] {
|
||||||
|
const ranges = [];
|
||||||
|
const startDate = new Date('2024-10-06T00:00:00Z').getTime();
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const start = startDate + Math.floor(Math.random() * 10000000); // Random start time
|
||||||
|
const end = start + Math.floor(Math.random() * 10000000); // Random end time after start
|
||||||
|
ranges.push({ start, end });
|
||||||
|
}
|
||||||
|
return ranges;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Benchmark performance of overlap detection between two schedulers
|
||||||
|
const schedulerA = generateTimeRanges(50);
|
||||||
|
const schedulerB = generateTimeRanges(50);
|
||||||
|
|
||||||
|
console.time('Overlap Benchmark');
|
||||||
|
let overlapCount = 0;
|
||||||
|
for (const rangeA of schedulerA) {
|
||||||
|
for (const rangeB of schedulerB) {
|
||||||
|
if (isOverlap(rangeA.start, rangeA.end, rangeB.start, rangeB.end)) {
|
||||||
|
overlapCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.timeEnd('Overlap Benchmark');
|
||||||
|
|
||||||
|
console.log(`Total Overlaps Found: ${overlapCount}`);
|
||||||
|
|
||||||
|
// Example usage with specific time ranges
|
||||||
|
const startA = new Date('2024-10-06T10:00:00Z').getTime();
|
||||||
|
const endA = new Date('2024-10-06T12:00:00Z').getTime();
|
||||||
|
const startB = new Date('2024-10-06T11:00:00Z').getTime();
|
||||||
|
const endB = new Date('2024-10-06T13:00:00Z').getTime();
|
||||||
|
|
||||||
|
const overlapRange = getOverlapRange(startA, endA, startB, endB);
|
||||||
|
if (overlapRange) {
|
||||||
|
console.log(
|
||||||
|
`Overlap Start: ${new Date(overlapRange.overlapStart).toISOString()}`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`Overlap End: ${new Date(overlapRange.overlapEnd).toISOString()}`
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Is overlap: true');
|
||||||
|
} else {
|
||||||
|
console.log('No overlap');
|
||||||
|
}
|
||||||
46
src/restful/restful.controller.ts
Normal file
46
src/restful/restful.controller.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { Controller, Get, Post, Put, Delete, Param, Body } from '@nestjs/common';
|
||||||
|
import { RestfulService } from './restful.service';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('Restful')
|
||||||
|
@Controller('restful')
|
||||||
|
export class RestfulController {
|
||||||
|
constructor(private readonly restfulService: RestfulService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
@ApiOperation({ summary: 'Get all items' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Returns all items.' })
|
||||||
|
getAllItems() {
|
||||||
|
return this.restfulService.getAllItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
@ApiOperation({ summary: 'Get an item by ID' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Returns the item with the given ID.' })
|
||||||
|
getItem(@Param('id') id: string) {
|
||||||
|
return this.restfulService.getItem(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
@ApiOperation({ summary: 'Create a new item' })
|
||||||
|
@ApiResponse({ status: 201, description: 'The item has been successfully created.' })
|
||||||
|
createItem(@Body() createDto: any) {
|
||||||
|
return this.restfulService.createItem(createDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put(':id')
|
||||||
|
@ApiOperation({ summary: 'Update an item' })
|
||||||
|
@ApiResponse({ status: 200, description: 'The item has been successfully updated.' })
|
||||||
|
updateItem(@Param('id') id: string, @Body() updateDto: any) {
|
||||||
|
return this.restfulService.updateItem(id, updateDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
@ApiOperation({ summary: 'Delete an item' })
|
||||||
|
@ApiResponse({ status: 200, description: 'The item has been successfully deleted.' })
|
||||||
|
deleteItem(@Param('id') id: string) {
|
||||||
|
return this.restfulService.deleteItem(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RestfulController;
|
||||||
0
src/users/dto/create-user.dto.ts
Normal file
0
src/users/dto/create-user.dto.ts
Normal file
0
src/users/dto/update-user.dto.ts
Normal file
0
src/users/dto/update-user.dto.ts
Normal file
Reference in New Issue
Block a user