-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8e0868
commit 414fc31
Showing
6 changed files
with
254 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
VFiniteNumber, | ||
VHumanString, | ||
VInteger, | ||
VStruct, | ||
Valid, | ||
} from "@wzlin/valid"; | ||
import assertInstanceOf from "@xtjs/lib/assertInstanceOf"; | ||
import { QueryGroupByOutput, makeQuery } from "../query"; | ||
|
||
const input = new VStruct({ | ||
query: new VHumanString(1, 512), | ||
simMinHundredths: new VInteger(80, 100), | ||
}); | ||
|
||
export const endpointAnalyzeSentiment = { | ||
input, | ||
handler: async ({ query, simMinHundredths }: Valid<typeof input>) => { | ||
const res = await makeQuery({ | ||
dataset: "comment", | ||
queries: [query], | ||
thresholds: { | ||
sim: simMinHundredths / 100, | ||
sent_pos: 0.5, | ||
sent_neg: 0.5, | ||
}, | ||
post_filter_clip: { | ||
sim_thresh: { min: 1.0, max: 1.0 }, | ||
}, | ||
outputs: [ | ||
{ | ||
group_by: { | ||
by: "ts_day", | ||
bucket: 7, | ||
cols: [ | ||
["sent_pos_thresh", "sum"], | ||
["sent_neg_thresh", "sum"], | ||
], | ||
}, | ||
}, | ||
], | ||
}); | ||
const data = assertInstanceOf(res[0], QueryGroupByOutput); | ||
return { | ||
timestamps: [...data.groups(new VInteger())].map( | ||
(d) => new Date(d * 7 * 24 * 60 * 60 * 1000), | ||
), | ||
positives: [...data.column("sent_pos_thresh", new VFiniteNumber())], | ||
negatives: [...data.column("sent_neg_thresh", new VFiniteNumber())], | ||
}; | ||
}, | ||
}; |
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,55 @@ | ||
import { | ||
VHumanString, | ||
VInteger, | ||
VMember, | ||
VStruct, | ||
VTuple, | ||
Valid, | ||
} from "@wzlin/valid"; | ||
import assertInstanceOf from "@xtjs/lib/assertInstanceOf"; | ||
import { QueryHeatmapOutput, makeQuery } from "../query"; | ||
|
||
const input = new VStruct({ | ||
query: new VHumanString(1, 512), | ||
dataset: new VMember(["post", "toppost"] as const), | ||
color: new VTuple([ | ||
new VInteger(0, 255), | ||
new VInteger(0, 255), | ||
new VInteger(0, 255), | ||
] as const), | ||
}); | ||
|
||
export const endpointHeatmap = { | ||
input, | ||
handler: async ({ dataset, query, color }: Valid<typeof input>) => { | ||
const res = await makeQuery({ | ||
dataset, | ||
queries: [query], | ||
scales: { | ||
sim: { | ||
post: { min: 0.7, max: 1 }, | ||
toppost: { min: 0.55, max: 1 }, | ||
}[dataset], | ||
}, | ||
post_filter_clip: { | ||
scaled: { min: 0.01, max: 1 }, | ||
}, | ||
weights: { | ||
sim_scaled: 1, | ||
}, | ||
outputs: [ | ||
{ | ||
heatmap: { | ||
alpha_scale: 2, // TODO This is really a hack, investigate distribution of scores. | ||
density: 25, | ||
color, | ||
upscale: 2, | ||
sigma: 4, | ||
}, | ||
}, | ||
], | ||
}); | ||
const data = assertInstanceOf(res[0], QueryHeatmapOutput); | ||
return new Uint8Array(data.raw); | ||
}, | ||
}; |
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
Oops, something went wrong.