This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
generated from mrbrianevans/react-website-template
-
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.
Completed YouTubeSearchAndWatchHistory link GH-60
Also finished the architecture to enable data linking across multiple files. Signed-off-by: Brian Evans <[email protected]>
- Loading branch information
1 parent
c317122
commit 57b0bf5
Showing
10 changed files
with
130 additions
and
39 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
9 changes: 6 additions & 3 deletions
9
client/src/visualisations/linked/YouTubeSearchAndWatchHistory.svelte
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<script> | ||
<script lang='ts'> | ||
import { YoutubeWatchSearchHistory } from '../../../../lib/linking/processors/youtubeWatchSearchHistory' | ||
import JsonEditor from '../../components/JsonEditor.svelte' | ||
import { minuteDifference } from '../../../../lib/common/DateUtils' | ||
export let data: YoutubeWatchSearchHistory | ||
</script> | ||
|
||
<div> | ||
<JsonEditor data={data} /> | ||
{#each data as { search, video }} | ||
<p>You searched <b>{search.searchTerm}</b> on {search.date} and then watched <b>{video.video}</b> by {video.channel} | ||
within five minutes. ({minuteDifference(video.date, search.date).toFixed(0)} minutes later)</p> | ||
{/each} | ||
</div> |
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
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 |
---|---|---|
@@ -1,30 +1,75 @@ | ||
import { PostProcessedOutput, PostProcessor } from '../typedefs/PostProcess' | ||
import { YoutubeWatchSearchHistoryLinkedProcessor } from './processors/youtubeWatchSearchHistory' | ||
import { ComponentName } from '../typedefs/Components' | ||
import type { ComponentName } from '../typedefs/Components' | ||
import type { ProcessedFile } from '../processFileContent' | ||
import type { PostProcessorCategory } from '../postProcessing/postProcessingCategoriser' | ||
|
||
// every time a new file is added, check if there is the right combination for this list | ||
|
||
export type LinkedProcessor = ( | ||
/** | ||
* an array of PostProcessedOutputs of the matching data sources | ||
*/ | ||
inputs: PostProcessedOutput[] | ||
) => PostProcessedOutput | null | ||
inputs: ProcessedFile[] | ||
) => ProcessedFile | null | ||
|
||
interface LinkedDataSource { | ||
linker: LinkedProcessor | ||
requiredPostprocessorCodes: string[] | ||
requiredPostprocessorCodes: PostProcessorCategory[] | ||
component: ComponentName | ||
} | ||
|
||
export const linkedDataSources: LinkedDataSource[] = [ | ||
// the necessary postprocessed data sources, the linker (which is a post processor itself) | ||
{ | ||
requiredPostprocessorCodes: [ | ||
'youtube-watch-history', | ||
'youtube-search-history' | ||
'YouTubeWatchHistoryPostProcess', | ||
'YouTubeSearchHistoryPostProcess' | ||
], | ||
linker: YoutubeWatchSearchHistoryLinkedProcessor, | ||
component: 'YouTubeSearchAndWatchHistory' | ||
} | ||
] | ||
|
||
export function linkDataSource( | ||
dataSource: ProcessedFile, | ||
dataSources: ProcessedFile[] | ||
): ProcessedFile[] { | ||
console.log('Finding links between datasources') | ||
const links = [] | ||
linkers: for (const linkedDataSource of linkedDataSources) { | ||
console.log('testing linker:', linkedDataSource.component) | ||
if ( | ||
!linkedDataSource.requiredPostprocessorCodes.includes( | ||
dataSource.metadata.postProcessingCategory | ||
) | ||
) { | ||
// requirements don't include the new data source | ||
continue | ||
} | ||
|
||
for (const requirement of linkedDataSource.requiredPostprocessorCodes) { | ||
if ( | ||
dataSources.every( | ||
(ds) => ds.metadata.postProcessingCategory !== requirement | ||
) && | ||
dataSource.metadata.postProcessingCategory !== requirement | ||
) { | ||
// this requirement is not met | ||
continue linkers | ||
} | ||
} | ||
// requirements are met | ||
links.push( | ||
linkedDataSource.linker( | ||
dataSources | ||
.filter((d) => | ||
linkedDataSource.requiredPostprocessorCodes.includes( | ||
d.metadata.postProcessingCategory | ||
) | ||
) | ||
.concat(dataSource) | ||
) | ||
) | ||
} | ||
return links | ||
} |
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
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