Remove stddev and direction columns

This commit is contained in:
Joscha 2023-10-21 18:20:37 +02:00
parent 0d48e0791b
commit 2bf939186d
10 changed files with 32 additions and 116 deletions

View file

@ -1,6 +1,6 @@
{ {
"db_name": "SQLite", "db_name": "SQLite",
"query": "SELECT metric, value, stddev, unit, direction FROM run_measurements WHERE id = ? ORDER BY metric ASC ", "query": "SELECT metric, value, unit FROM run_measurements WHERE id = ? ORDER BY metric ASC ",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -13,20 +13,10 @@
"ordinal": 1, "ordinal": 1,
"type_info": "Float" "type_info": "Float"
}, },
{
"name": "stddev",
"ordinal": 2,
"type_info": "Float"
},
{ {
"name": "unit", "name": "unit",
"ordinal": 3, "ordinal": 2,
"type_info": "Text" "type_info": "Text"
},
{
"name": "direction",
"ordinal": 4,
"type_info": "Int64"
} }
], ],
"parameters": { "parameters": {
@ -35,10 +25,8 @@
"nullable": [ "nullable": [
false, false,
false, false,
true,
true,
true true
] ]
}, },
"hash": "0a4a3c4090e70ca643c4af0368ecf5c8dde66d898a900afa299a94e9a7bc62f8" "hash": "185c3516e116876f1783f25ffeb179ca6ecb4f9a001a48127516a81b7a50062a"
} }

View file

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO run_measurements ( id, metric, value, unit ) VALUES (?, ?, ?, ?) ",
"describe": {
"columns": [],
"parameters": {
"Right": 4
},
"nullable": []
},
"hash": "8fa4d1546e559bca47e2fb765ee33b989271492395b43c1887db7d490d9dff8d"
}

View file

@ -1,12 +0,0 @@
{
"db_name": "SQLite",
"query": "INSERT INTO run_measurements ( id, metric, value, stddev, unit, direction ) VALUES (?, ?, ?, ?, ?, ?) ",
"describe": {
"columns": [],
"parameters": {
"Right": 6
},
"nullable": []
},
"hash": "971b811933eb0ab6ae4f23d6179f7035be88c7134b05118c20b106f10d299fe9"
}

View file

@ -6,14 +6,9 @@ import json
import math import math
import re import re
import sqlite3 import sqlite3
import statistics
import urllib.request import urllib.request
DIRECTION = {
"LESS_IS_BETTER": -1,
"NEUTRAL": 0,
"MORE_IS_BETTER": 1,
}
def format_time(time): def format_time(time):
# If the fractional part of the second is not exactly 3 or 6 digits long, # If the fractional part of the second is not exactly 3 or 6 digits long,
@ -31,15 +26,6 @@ def format_time(time):
return time.isoformat() return time.isoformat()
def stddev(values):
if len(values) < 2:
return None
N = len(values)
mean = sum(values) / N
variance = sum(pow(value - mean, 2) for value in values) / (N - 1)
return math.sqrt(variance)
def get_run_data(con, run_id): def get_run_data(con, run_id):
( (
runner_name, runner_name,
@ -73,7 +59,6 @@ def get_run_data(con, run_id):
benchmark, benchmark,
metric, metric,
unit, unit,
interpretation,
error, error,
) in con.execute( ) in con.execute(
""" """
@ -82,7 +67,6 @@ def get_run_data(con, run_id):
benchmark, benchmark,
metric, metric,
unit, unit,
interpretation,
error error
FROM measurement FROM measurement
WHERE run_id = ? WHERE run_id = ?
@ -101,10 +85,8 @@ def get_run_data(con, run_id):
values = [value for (value,) in values] values = [value for (value,) in values]
measurements[f"{metric}/{benchmark}"] = { measurements[f"{metric}/{benchmark}"] = {
"value": sum(values), "value": statistics.mean(values),
"stddev": stddev(values),
"unit": unit, "unit": unit,
"direction": DIRECTION.get(interpretation),
} }
if error_type: if error_type:

View file

@ -43,9 +43,7 @@ CREATE TABLE run_measurements (
id TEXT NOT NULL, id TEXT NOT NULL,
metric TEXT NOT NULL, metric TEXT NOT NULL,
value REAL NOT NULL, value REAL NOT NULL,
stddev REAL,
unit TEXT, unit TEXT,
direction INT,
PRIMARY KEY (id, metric), PRIMARY KEY (id, metric),
FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE

View file

@ -81,18 +81,14 @@ async fn save_work(
id, \ id, \
metric, \ metric, \
value, \ value, \
stddev, \ unit \
unit, \
direction \
) \ ) \
VALUES (?, ?, ?, ?, ?, ?) \ VALUES (?, ?, ?, ?) \
", ",
run.id, run.id,
metric, metric,
measurement.value, measurement.value,
measurement.stddev,
measurement.unit, measurement.unit,
measurement.direction,
) )
.execute(&mut *conn) .execute(&mut *conn)
.await?; .await?;

View file

@ -23,9 +23,7 @@ use crate::{
struct Measurement { struct Measurement {
metric: String, metric: String,
value: String, value: String,
stddev: String,
unit: String, unit: String,
direction: &'static str,
} }
struct Line { struct Line {
@ -83,9 +81,7 @@ async fn from_finished_run(
SELECT \ SELECT \
metric, \ metric, \
value, \ value, \
stddev, \ unit \
unit, \
direction \
FROM run_measurements \ FROM run_measurements \
WHERE id = ? \ WHERE id = ? \
ORDER BY metric ASC \ ORDER BY metric ASC \
@ -96,14 +92,7 @@ async fn from_finished_run(
.map_ok(|r| Measurement { .map_ok(|r| Measurement {
metric: r.metric, metric: r.metric,
value: util::format_value(r.value), value: util::format_value(r.value),
stddev: r.stddev.map(util::format_value).unwrap_or_default(),
unit: r.unit.unwrap_or_default(), unit: r.unit.unwrap_or_default(),
direction: match r.direction {
Some(..=-1) => "less is better",
Some(0) => "neutral",
Some(1..) => "more is better",
None => "",
},
}) })
.try_collect::<Vec<_>>() .try_collect::<Vec<_>>()
.await?; .await?;

View file

@ -55,14 +55,8 @@ pub enum Direction {
pub struct Measurement { pub struct Measurement {
pub value: f64, pub value: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub stddev: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub unit: Option<String>, pub unit: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub direction: Option<Direction>,
} }
#[derive(Clone, Serialize, Deserialize)] #[derive(Clone, Serialize, Deserialize)]

View file

@ -8,11 +8,7 @@ use std::{
use regex::RegexBuilder; use regex::RegexBuilder;
use walkdir::WalkDir; use walkdir::WalkDir;
use crate::{ use crate::{shared::Measurement, somehow, worker::server::Server};
shared::{Direction, Measurement},
somehow,
worker::server::Server,
};
use super::{Finished, RunInProgress}; use super::{Finished, RunInProgress};
@ -110,70 +106,47 @@ fn count(path: &Path) -> somehow::Result<Counts> {
Ok(counts) Ok(counts)
} }
fn measurement(value: f64, direction: Direction) -> Measurement { fn measurement(value: f64) -> Measurement {
Measurement { Measurement { value, unit: None }
value,
stddev: None,
unit: None,
direction: Some(direction),
}
} }
fn measurements(counts: Counts) -> HashMap<String, Measurement> { fn measurements(counts: Counts) -> HashMap<String, Measurement> {
let mut measurements = HashMap::new(); let mut measurements = HashMap::new();
// Files // Files
measurements.insert( measurements.insert("files".to_string(), measurement(counts.files as f64));
"files".to_string(),
measurement(counts.files as f64, Direction::Neutral),
);
for (ext, count) in counts.files_by_ext { for (ext, count) in counts.files_by_ext {
measurements.insert( measurements.insert(
format!("files/by extension/{ext}"), format!("files/by extension/{ext}"),
measurement(count as f64, Direction::Neutral), measurement(count as f64),
); );
} }
for (dir, count) in counts.files_by_dir { for (dir, count) in counts.files_by_dir {
measurements.insert( measurements.insert(format!("files/by dir/{dir}/"), measurement(count as f64));
format!("files/by dir/{dir}/"),
measurement(count as f64, Direction::Neutral),
);
} }
// Lines // Lines
measurements.insert( measurements.insert("lines".to_string(), measurement(counts.lines as f64));
"lines".to_string(),
measurement(counts.lines as f64, Direction::Neutral),
);
for (ext, count) in counts.lines_by_ext { for (ext, count) in counts.lines_by_ext {
measurements.insert( measurements.insert(
format!("lines/by extension/{ext}"), format!("lines/by extension/{ext}"),
measurement(count as f64, Direction::Neutral), measurement(count as f64),
); );
} }
for (dir, count) in counts.lines_by_dir { for (dir, count) in counts.lines_by_dir {
measurements.insert( measurements.insert(format!("lines/by dir/{dir}/"), measurement(count as f64));
format!("lines/by dir/{dir}/"),
measurement(count as f64, Direction::Neutral),
);
} }
// Todos // Todos
measurements.insert( measurements.insert("todos".to_string(), measurement(counts.todos as f64));
"todos".to_string(),
measurement(counts.todos as f64, Direction::LessIsBetter),
);
for (ext, count) in counts.todos_by_ext { for (ext, count) in counts.todos_by_ext {
measurements.insert( measurements.insert(
format!("todos/by extension/{ext}"), format!("todos/by extension/{ext}"),
measurement(count as f64, Direction::LessIsBetter), measurement(count as f64),
); );
} }
for (dir, count) in counts.todos_by_dir { for (dir, count) in counts.todos_by_dir {
measurements.insert( measurements.insert(format!("todos/by dir/{dir}/"), measurement(count as f64));
format!("todos/by dir/{dir}/"),
measurement(count as f64, Direction::LessIsBetter),
);
} }
measurements measurements

View file

@ -36,9 +36,7 @@
<tr> <tr>
<th>metric</th> <th>metric</th>
<th>value</th> <th>value</th>
<th>stddev</th>
<th>unit</th> <th>unit</th>
<th>direction</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -46,9 +44,7 @@
<tr> <tr>
<td>{{ mm.metric }}</td> <td>{{ mm.metric }}</td>
<td>{{ mm.value }}</td> <td>{{ mm.value }}</td>
<td>{{ mm.stddev }}</td>
<td>{{ mm.unit }}</td> <td>{{ mm.unit }}</td>
<td>{{ mm.direction }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>