-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove console.log
- Loading branch information
Showing
10 changed files
with
408 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore | ||
|
||
# Logs | ||
|
||
logs | ||
_.log | ||
npm-debug.log_ | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Caches | ||
|
||
.cache | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
|
||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
||
# Runtime data | ||
|
||
pids | ||
_.pid | ||
_.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
|
||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
|
||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
|
||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
|
||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
|
||
bower_components | ||
|
||
# node-waf configuration | ||
|
||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
|
||
build/Release | ||
|
||
# Dependency directories | ||
|
||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
|
||
web_modules/ | ||
|
||
# TypeScript cache | ||
|
||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
|
||
.npm | ||
|
||
# Optional eslint cache | ||
|
||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
|
||
.stylelintcache | ||
|
||
# Microbundle cache | ||
|
||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
|
||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
|
||
*.tgz | ||
|
||
# Yarn Integrity file | ||
|
||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
|
||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
|
||
.parcel-cache | ||
|
||
# Next.js build output | ||
|
||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
|
||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
|
||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
|
||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
|
||
# public | ||
|
||
# vuepress build output | ||
|
||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
|
||
.temp | ||
|
||
# Docusaurus cache and generated files | ||
|
||
.docusaurus | ||
|
||
# Serverless directories | ||
|
||
.serverless/ | ||
|
||
# FuseBox cache | ||
|
||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
|
||
.dynamodb/ | ||
|
||
# TernJS port file | ||
|
||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
|
||
.vscode-test | ||
|
||
# yarn v2 | ||
|
||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# IntelliJ based IDEs | ||
.idea | ||
|
||
# Finder (MacOS) folder config | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Dime.Scheduler SDK for JavaScript sample: Ping Pong | ||
|
||
## Getting started | ||
|
||
Install the dependencies | ||
|
||
```cmd | ||
bun install | ||
``` | ||
|
||
Create an `.env` file with the Mapbox and Dime.Scheduler API keys: | ||
|
||
``` | ||
DS_API_KEY= | ||
``` | ||
|
||
There are two commands that you can run: `stage` and `play`. | ||
|
||
The `stage` command is create the playing field. It requires three sets of information: the start date (parameter 's'), the end date (parameter 'e'), and a list of resources to create appointments for: | ||
|
||
``` | ||
bun stage -s '2022-04-03' -e '2022-04-09' -r 'ARNOUD' -r 'ASSIA' -r 'ELSEMIEK' -r 'HESSEL' | ||
``` | ||
|
||
The `play` command accepts the same parameters: | ||
|
||
``` | ||
bun play -s '2022-04-03' -e '2022-04-09' -r 'ARNOUD' -r 'ASSIA' -r 'ELSEMIEK' -r 'HESSEL' | ||
``` | ||
|
||
## Application in action | ||
|
||
![](./assets/pingpong.gif) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "pingpong", | ||
"module": "index.ts", | ||
"type": "module", | ||
"scripts": { | ||
"stage": "bun run stage.ts", | ||
"play": "bun run play.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "latest" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"commander": "^12.0.0", | ||
"dimescheduler": "^0.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Command } from 'commander'; | ||
import DimeSchedulerClient, { Environment } from 'dimescheduler'; | ||
import { Appointment } from 'dimescheduler/models'; | ||
const program = new Command(); | ||
|
||
const collect = (val: any, memo: any[]) => { | ||
memo.push(val); | ||
return memo; | ||
} | ||
|
||
program | ||
.requiredOption('-s, --start <startdate>', 'Start date') | ||
.requiredOption('-e, --end <enddate>', 'End date') | ||
.requiredOption('-r, --resources <items>', 'Resources', collect, []); | ||
|
||
program.parse(process.argv); | ||
|
||
const options = program.opts(); | ||
|
||
const createBall = async (client: DimeSchedulerClient, startDate: string) => { | ||
const endOfDay = new Date(startDate); | ||
endOfDay.setDate(endOfDay.getDate() + 1); | ||
|
||
const appointment = new Appointment(); | ||
appointment.resourceNo = options.resources[1]; | ||
appointment.start = startDate; | ||
appointment.end = endOfDay.toISOString(); | ||
appointment.sourceApp = "PINGPONG"; | ||
appointment.sourceType = "PINGPONG"; | ||
appointment.jobNo = "PINGPONG"; | ||
appointment.taskNo = "PINGPONG"; | ||
appointment.category = "PINGPONG"; | ||
appointment.appointmentGuid = "dbc77ca8-f7b8-4bc7-9877-d63d57a81210"; | ||
|
||
await client.import(appointment); | ||
} | ||
|
||
const client = new DimeSchedulerClient(Bun.env.DS_API_KEY as string, Environment.Test); | ||
|
||
const play = async () => { | ||
let start = new Date(options.start); | ||
start.setDate(start.getDate() + 1); | ||
|
||
let end = new Date(options.end); | ||
end.setDate(end.getDate() - 1); | ||
|
||
const dates = getDateRange(start, end); | ||
for (const date of dates) { | ||
await createBall(client, date.toISOString().split('T')[0]); | ||
await Bun.sleep(500); | ||
} | ||
} | ||
|
||
const getDateRange = (startDate: Date, endDate: Date): Date[] => { | ||
const dates = []; | ||
let currentDate = new Date(startDate); | ||
|
||
while (currentDate <= endDate) { | ||
dates.push(new Date(currentDate)); | ||
currentDate.setDate(currentDate.getDate() + 1); | ||
} | ||
|
||
return [...dates, ...dates.slice().reverse()]; | ||
} | ||
|
||
let iterations = 0; | ||
async function repeatAsyncFunctionSynchronously() { | ||
let finished = false; | ||
let result; | ||
|
||
while (!finished) { | ||
try { | ||
result = await play(); | ||
iterations++; | ||
if (iterations > 5) | ||
finished = true; | ||
} catch (error) { | ||
console.error("Error occurred:", error); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
repeatAsyncFunctionSynchronously(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Command } from 'commander'; | ||
import DimeSchedulerClient, { Environment } from 'dimescheduler'; | ||
import { Appointment, Category, Job, Task } from 'dimescheduler/models'; | ||
const program = new Command(); | ||
|
||
const collect = (val: any, memo: any[]) => { | ||
memo.push(val); | ||
return memo; | ||
} | ||
|
||
program | ||
.requiredOption('-s, --start <startdate>', 'Start date') | ||
.requiredOption('-e, --end <enddate>', 'End date') | ||
.requiredOption('-r, --resources <items>', 'Resources', collect, []); | ||
|
||
program.parse(process.argv); | ||
|
||
const options = program.opts(); | ||
const createBallColor = async (client: DimeSchedulerClient) => { | ||
const ballColor = new Category(); | ||
ballColor.name = "PINGPONG"; | ||
ballColor.color = "#FF65D4"; | ||
await client.import(ballColor); | ||
} | ||
|
||
// Need to create a job and a task for appointments to arrive on the planning board | ||
const createJobTask = async (client: DimeSchedulerClient) => { | ||
const job = new Job(); | ||
job.SourceApp = "PINGPONG"; | ||
job.SourceType = "PINGPONG"; | ||
job.JobNo = "PINGPONG"; | ||
job.ShortDescription = "PING PONG SAMPLE"; | ||
await client.import(job); | ||
|
||
const task = new Task(); | ||
task.sourceApp = "PINGPONG"; | ||
task.sourceType = "PINGPONG"; | ||
task.jobNo = "PINGPONG"; | ||
task.taskNo = "PINGPONG"; | ||
task.shortDescription = "PING PONG SAMPLE"; | ||
await client.import(task); | ||
} | ||
|
||
const createPlayer = async (client: DimeSchedulerClient, date: Date, resourceNo: string) => { | ||
const start = new Date(date); | ||
const endOfDay = new Date(date); | ||
endOfDay.setDate(endOfDay.getDate() + 1); | ||
|
||
const appointment = new Appointment(); | ||
appointment.resourceNo = resourceNo; | ||
appointment.start = start.toISOString(); | ||
appointment.end = endOfDay.toISOString(); | ||
appointment.sourceApp = "PINGPONG"; | ||
appointment.sourceType = "PINGPONG"; | ||
appointment.jobNo = "PINGPONG"; | ||
appointment.taskNo = "PINGPONG"; | ||
|
||
await client.import(appointment); | ||
} | ||
|
||
const client = new DimeSchedulerClient(Bun.env.DS_API_KEY as string, Environment.Test); | ||
await createJobTask(client); | ||
await createBallColor(client); | ||
|
||
for (const resource of options.resources) { | ||
await createPlayer(client, options.start, resource); | ||
await createPlayer(client, options.end, resource); | ||
} |
Oops, something went wrong.