make experience more specific

This commit is contained in:
41666 2023-06-29 15:30:29 -04:00
parent 143ec0cd3b
commit a1f0e32e30
3 changed files with 69 additions and 7 deletions

View file

@ -24,7 +24,16 @@ impl Analytics {
) -> Vec<Event> {
let pool = ctx.data::<Pool<Postgres>>().unwrap();
let sql = format!("SELECT time_bucket_gapfill('{} seconds', time, start => now() - '{}'::interval, finish => now()) AS bucket, CASE WHEN count(*) IS NULL THEN 0 ELSE count(*) END AS count, event_name, world_id FROM analytics WHERE event_name IN ('Death', 'VehicleDestroy', 'GainExperience') AND time > now() - '{}'::interval {} GROUP BY bucket, world_id, event_name ORDER BY bucket ASC",
let sql = format!("
SELECT
time_bucket_gapfill('{} seconds', time, start => now() - '{}'::interval, finish => now()) AS bucket,
CASE WHEN count(*) IS NULL THEN 0 ELSE count(*) END AS count,
event_name,
world_id
FROM analytics
WHERE time > now() - '{}'::interval {}
GROUP BY bucket, world_id, event_name
ORDER BY bucket ASC",
if hi_precision {
5
} else {

View file

@ -147,6 +147,15 @@
<canvas id="ceres" />
</div>
</div>
<div class="wide">
<div class="graph-head">
<h3>Experience Events By ID</h3>
<p class="exp-sums">(0, 0, 0, 0)</p>
</div>
<div class="chart-container">
<canvas id="exp-by-id" />
</div>
</div>
</div>
<p>
[<a href="/">home</a>] [<a href="/ingest">1 day w/ 5m buckets</a>] [<a
@ -204,7 +213,9 @@
doSums(id, events);
let allEvents = events.reduce(
(acc, ev) => {
acc[ev.eventName][ev.time] = (acc[ev.time] || 0) + ev.count;
const eventName = ev.eventName.replace(/_[0-9]+/g, "");
acc[eventName][ev.time] = acc[eventName][ev.time] ?? 0;
acc[eventName][ev.time] += ev.count;
return acc;
},
{ Death: {}, VehicleDestroy: {}, GainExperience: {} }
@ -215,7 +226,7 @@
options: {
scales: {
y: { beginAtZero: true, suggestedMin: 0 },
x: { stacked: true, type: "timeseries" },
x: { stacked: false, type: "timeseries" },
},
},
data: {
@ -237,6 +248,37 @@
});
};
const experienceEventsByID = (eventsUnfiltered) => {
const events = eventsUnfiltered.filter((ev) =>
ev.eventName.startsWith("GainExperience_")
);
doSums("exp-by-id", events);
let allEvents = events.reduce((acc, ev) => {
const eventID = ev.eventName.replace(/GainExperience_([0-9]+)/g, "$1");
acc[eventID] = acc[eventID] ?? {};
acc[eventID][ev.time] = acc[eventID][ev.time] ?? 0;
acc[eventID][ev.time] += ev.count;
return acc;
}, {});
new Chart(document.getElementById("exp-by-id"), {
type: "bar",
options: {
scales: {
y: { beginAtZero: true, suggestedMin: 0 },
x: { stacked: true, type: "timeseries" },
},
},
data: {
datasets: Object.keys(allEvents).map((id) => ({
label: id,
data: allEvents[id],
})),
},
});
};
const eventsByWorld = (events) => {
let allEvents = events.reduce((acc, ev) => {
acc[ev.worldId] = acc[ev.worldId] || {};
@ -341,5 +383,6 @@
let worldEvents = events.filter((ev) => ev.worldId === id);
allEventsByType(world, worldEvents);
});
experienceEventsByID(events);
})();
</script>

View file

@ -66,6 +66,7 @@ struct PopEvent {
vehicle_id: String,
}
#[derive(Debug)]
struct AnalyticsEvent {
world_id: i32,
event_name: String,
@ -150,7 +151,7 @@ async fn track_pop(pop_event: PopEvent) {
}
async fn track_analytics(analytics_event: AnalyticsEvent) {
// println!("[ws/track_analytics]");
// println!("[ws/track_analytics] {:?}", analytics_event);
let pool = PG.get().await;
let AnalyticsEvent {
@ -158,12 +159,17 @@ async fn track_analytics(analytics_event: AnalyticsEvent) {
event_name,
} = analytics_event;
query("INSERT INTO analytics (time, world_id, event_name) VALUES (now(), $1, $2);")
match query("INSERT INTO analytics (time, world_id, event_name) VALUES (now(), $1, $2);")
.bind(world_id)
.bind(event_name)
.execute(pool)
.await
.unwrap();
{
Ok(_) => {}
Err(e) => {
println!("[ws/track_analytics] ERR => {:?}", e);
}
}
}
async fn process_death_event(event: &Event) {
@ -209,7 +215,11 @@ async fn process_exp_event(event: &Event) {
set.spawn(track_analytics(AnalyticsEvent {
world_id: event.world_id.clone(),
event_name: event.event_name.clone(),
event_name: format!(
"{}_{}",
event.event_name.clone(),
event.experience_id.clone()
),
}));
// Vehicle EXP events