-
Notifications
You must be signed in to change notification settings - Fork 6
Heatmap #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Heatmap #234
Changes from all commits
c1c30fb
cf25911
b89481b
9ec5191
afb42cc
4d27f23
eb96455
4e5d29a
89c21ab
b40be5e
0b52cae
3e3ecb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,17 +26,14 @@ | |
| import type { Tours } from '$lib/server/db/getTours'; | ||
| import Message from '$lib/ui/Message.svelte'; | ||
| import type { UnixtimeMs } from '$lib/util/UnixtimeMs'; | ||
| import type { Range } from './Range'; | ||
| import { split } from './Range'; | ||
| import type { LngLatLike } from 'maplibre-gl'; | ||
| const { data, form } = $props(); | ||
| type Vehicle = NonNullable<typeof data.vehicles>[0]; | ||
| type Range = { | ||
| startTime: UnixtimeMs; | ||
| endTime: UnixtimeMs; | ||
| }; | ||
| // === | ||
| // API | ||
| // --- | ||
|
|
@@ -133,18 +130,6 @@ | |
| const isAvailable = (v: Vehicle, cell: Range) => v.availability.some((a) => overlaps(a, cell)); | ||
| const split = (range: Range, size: number): Array<Range> => { | ||
| let cells: Array<Range> = []; | ||
| let prev = new Date(range.startTime); | ||
| let t = new Date(range.startTime); | ||
| t.setMinutes(t.getMinutes() + size); | ||
| for (; t.getTime() <= range.endTime; t.setMinutes(t.getMinutes() + size)) { | ||
| cells.push({ startTime: prev.getTime(), endTime: t.getTime() }); | ||
| prev = new Date(t); | ||
| } | ||
| return cells; | ||
| }; | ||
| // ========= | ||
| // Selection | ||
| // --------- | ||
|
|
@@ -299,6 +284,45 @@ | |
| return 'bg-yellow-100'; | ||
| } | ||
| }; | ||
| const heatmapColor = (cell: Range) => { | ||
| let max = 20; | ||
| for (let heat of data.heatarray) { | ||
| if (heat.cell.startTime == cell.startTime && heat.cell.endTime == cell.endTime) { | ||
| // logarithmisch für stark schwankende Werte: | ||
| //let normval = Math.floor(10 * (Math.log(heat.heat + 1)) / Math.log(max + 1)); | ||
| let normval = Math.floor((heat.heat / max) * 10); | ||
| normval = heat.heat > 0 ? Math.max(1, normval) : 0; | ||
| switch (normval) { | ||
| case 0: | ||
| return; | ||
| case 1: | ||
| return 'bg-rose-100'; | ||
| case 2: | ||
| return 'bg-rose-200'; | ||
| case 3: | ||
| return 'bg-rose-300'; | ||
| case 4: | ||
| return 'bg-rose-400'; | ||
| case 5: | ||
| return 'bg-rose-500'; | ||
| case 6: | ||
| return 'bg-rose-600'; | ||
| case 7: | ||
| return 'bg-rose-700'; | ||
| case 8: | ||
| return 'bg-rose-800'; | ||
| case 9: | ||
| return 'bg-rose-900'; | ||
| case 10: | ||
| return 'bg-rose-950'; | ||
| default: | ||
| return; | ||
|
Comment on lines
+297
to
+320
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unklar aus Nutzersicht was die Farbe bedeutet. |
||
| } | ||
| } | ||
| } | ||
| return; | ||
| }; | ||
| </script> | ||
|
|
||
| <svelte:window onmouseup={() => selectionFinish()} /> | ||
|
|
@@ -395,6 +419,37 @@ | |
| {/each} | ||
| </tr> | ||
| {/each} | ||
| <tr> | ||
| <td | ||
| class="h-full pr-2 align-middle font-mono text-sm font-semibold leading-none tracking-tight" | ||
| > | ||
| <HoverCard.Root> | ||
| <HoverCard.Trigger>{'Auslastung'}</HoverCard.Trigger> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warum Auslastung? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ich habe nach einem kurzen Wort gesucht, damit es gut in die Übersicht passt. Es sollte beschreiben, wie sehr der Zeitslot von den anderen Taxiunternehmern ausgelastet ist. |
||
| <HoverCard.Content> | ||
| <!-- Anpassen, wenn logarithmische Skalierung verwendet wird. --> | ||
| Eine Heatmap, die die Verfügbarkeiten der anderen Taxiunternehmer anzeigt. Farbcodierung: | ||
| linear, [1, 10] | ||
|
Comment on lines
+430
to
+431
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unklar aus Nutzersicht |
||
| </HoverCard.Content> | ||
| </HoverCard.Root> | ||
| </td> | ||
| {#each split(range, 60) as x} | ||
| <td> | ||
| <table class="w-full"> | ||
| <tbody> | ||
| <tr> | ||
| {#each split(x, 15) as cell} | ||
| <td> | ||
| <div | ||
| class={['w-8', 'h-8', 'border', 'rounded-md', heatmapColor(cell)].join(' ')} | ||
| ></div> | ||
| </td> | ||
| {/each} | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| </td> | ||
| {/each} | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| {/snippet} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { UnixtimeMs } from '$lib/util/UnixtimeMs'; | ||
|
|
||
| export type Range = { | ||
| startTime: UnixtimeMs; | ||
| endTime: UnixtimeMs; | ||
| }; | ||
|
|
||
| export function split(range: Range, size: number): Array<Range> { | ||
| const cells: Array<Range> = []; | ||
| let prev = new Date(range.startTime); | ||
| const t = new Date(range.startTime); | ||
| t.setMinutes(t.getMinutes() + size); | ||
| for (; t.getTime() <= range.endTime; t.setMinutes(t.getMinutes() + size)) { | ||
| cells.push({ startTime: prev.getTime(), endTime: t.getTime() }); | ||
| prev = new Date(t); | ||
| } | ||
| return cells; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicht nachvollziehabar aus Nutzersicht.