mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 05:47:07 +00:00
Clean up dead code
This commit is contained in:
@@ -46,19 +46,6 @@ async function groups () {
|
||||
return Object.fromEntries(groupNames.map( g => [g, projects.filter( p => p.groups.includes(g) )] ));
|
||||
}
|
||||
|
||||
/*
|
||||
async function compare (baselineProjectID, monitorProjectID) {
|
||||
console.log("Getting baseline", baselineProjectID);
|
||||
const baselineData = await db.sequence.get(baselineProjectID);
|
||||
console.log("Getting monitor", monitorProjectID);
|
||||
const monitorData = await db.sequence.get(monitorProjectID);
|
||||
console.log("Comparing");
|
||||
|
||||
const comparison = comparisonGeometricDifferences(baselineData, monitorData);
|
||||
return comparison;
|
||||
}
|
||||
*/
|
||||
|
||||
function geometric_differences (baseline, monitor) {
|
||||
|
||||
if (!baseline || !baseline.length) {
|
||||
@@ -160,67 +147,6 @@ async function save (baselineProjectID, monitorProjectID, bundle, meta) {
|
||||
}
|
||||
|
||||
|
||||
async function saveSample (baselineProjectID, monitorProjectID, opts = {}) {
|
||||
DEBUG("Not bothering to save samples. This feature will be removed.");
|
||||
}
|
||||
|
||||
/*
|
||||
async function saveSample (baselineProjectID, monitorProjectID, opts = {}) {
|
||||
let sample = opts.sample;
|
||||
let populationStats = opts.populationStats;
|
||||
let sampleStats = opts.sampleStats;
|
||||
|
||||
if (!sample?.length) {
|
||||
const sampleSize = opts.sampleSize ?? 2000;
|
||||
const record = await get(baselineProjectID, monitorProjectID);
|
||||
let data;
|
||||
|
||||
if (record) {
|
||||
data = record.data;
|
||||
} else {
|
||||
console.log("Full data not found in database");
|
||||
data = asBundle(await compare(baselineProjectID, monitorProjectID));
|
||||
}
|
||||
|
||||
sample = computeSample(data, opts);
|
||||
|
||||
if (!populationStats) {
|
||||
populationStats = stats(data);
|
||||
}
|
||||
}
|
||||
|
||||
const bundle = asBundle(sample, {type: 0x0c});
|
||||
|
||||
if (!sampleStats) {
|
||||
sampleStats = stats(bundle);
|
||||
}
|
||||
|
||||
meta = {tstamp: (new Date()), populationStats, sampleStats, ...(opts.meta??{})};
|
||||
|
||||
const client = await pool.connect();
|
||||
|
||||
try {
|
||||
const text = `
|
||||
INSERT INTO comparisons.comparisons
|
||||
(type, baseline_pid, monitor_pid, data, meta)
|
||||
VALUES ('geometric_difference_sample', $1, $2, $3, $4)
|
||||
ON CONFLICT (type, baseline_pid, monitor_pid)
|
||||
DO UPDATE SET
|
||||
data = EXCLUDED.data,
|
||||
meta = EXCLUDED.meta;
|
||||
`;
|
||||
|
||||
const values = [ baselineProjectID, monitorProjectID, Buffer.from(bundle), meta ];
|
||||
const res = await client.query(text, values);
|
||||
return res.rowCount;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
async function get (baselineProjectID, monitorProjectID, type = 'geometric_difference') {
|
||||
|
||||
const client = await pool.connect();
|
||||
@@ -328,77 +254,6 @@ function stats (comparison) {
|
||||
}
|
||||
|
||||
|
||||
/** Compare two projects' errorfinal quantities.
|
||||
*
|
||||
* Assumes that the preplots are the same.
|
||||
* It is not a terribly efficient way of doing it, but considering
|
||||
* that this is, by and large only going to be done once every few
|
||||
* hours for an active prospect, and never for inactive ones, I
|
||||
* think and hope we can live with that.
|
||||
*
|
||||
* `baseline` and `monitor` are the result of calling
|
||||
* db.sequence.get(projectId) on each of the respective
|
||||
* projects.
|
||||
*/
|
||||
/*
|
||||
function comparisonGeometricDifferences (baseline, monitor) {
|
||||
|
||||
if (!baseline || !baseline.length) {
|
||||
throw new Error("No baseline data");
|
||||
}
|
||||
|
||||
if (!monitor || !monitor.length) {
|
||||
throw new Error("No monitor data");
|
||||
}
|
||||
|
||||
const comparison = []; // An array of { line, point, εi, εj, δts }; line + point may be repeated
|
||||
|
||||
for (const bp of baseline) {
|
||||
if (!bp.errorfinal) {
|
||||
console.log(`No final data for baseline point L${bp.line} S${bp.sequence} P${bp.point}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const monitor_points = monitor.filter( mp => mp.line === bp.line && mp.point === bp.point );
|
||||
for (const mp of monitor_points) {
|
||||
if (!mp.errorfinal) {
|
||||
console.log(`No final data for monitor point L${mp.line} S${mp.sequence} P${mp.point}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const line = bp.line;
|
||||
const point = bp.point;
|
||||
const baseSeq = bp.sequence;
|
||||
const monSeq = mp.sequence;
|
||||
const baseTStamp = bp.tstamp;
|
||||
const monTStamp = mp.tstamp;
|
||||
const δi = bp.errorfinal.coordinates[0] - mp.errorfinal.coordinates[0];
|
||||
const δj = bp.errorfinal.coordinates[1] - mp.errorfinal.coordinates[1];
|
||||
|
||||
const obj = {line, point, baseSeq, monSeq, baseTStamp, monTStamp, δi, δj};
|
||||
comparison.push(obj);
|
||||
// console.log(obj);
|
||||
}
|
||||
}
|
||||
|
||||
return comparison.sort(sortFn);
|
||||
}
|
||||
|
||||
function sortComparison (comparison) {
|
||||
return comparison.sort( (a, b) => {
|
||||
if (a.line == b.line) {
|
||||
if (a.point == b.point) {
|
||||
return a.baseTStamp - b.baseTStamp;
|
||||
} else {
|
||||
return a.point - b.point;
|
||||
}
|
||||
} else {
|
||||
return a.line - b.line;
|
||||
}
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
function sortFn (a, b) {
|
||||
if (a.line == b.line) {
|
||||
if (a.point == b.point) {
|
||||
@@ -454,12 +309,7 @@ async function saveGroup (group, opts = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
const isSaved = await save(baselineProjectID, monitorProjectID);
|
||||
if (isSaved) {
|
||||
await saveSample(baselineProjectID, monitorProjectID, opts.sampleOpts);
|
||||
} else {
|
||||
await remove(baselineProjectID, monitorProjectID);
|
||||
}
|
||||
await save(baselineProjectID, monitorProjectID);
|
||||
DEBUG("Saved comparison between %s and %s", baselineProjectID, monitorProjectID);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@@ -469,44 +319,6 @@ async function saveGroup (group, opts = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
async function getGroup (groupName, opts = {}) {
|
||||
|
||||
const group = (await groups())?.[groupName]?.map( i => i.pid)?.sort();
|
||||
|
||||
if (!group?.length) return;
|
||||
|
||||
const client = await pool.connect();
|
||||
|
||||
try {
|
||||
|
||||
const text = `
|
||||
-- SQL query goes here
|
||||
`;
|
||||
|
||||
const values = combinations(group, 2);
|
||||
const res = await client.query(text, values);
|
||||
if (!res.rows.length) {
|
||||
console.log("Comparison not found in database");
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.returnData) {
|
||||
return res.rows.map( row => ({
|
||||
data: DougalBinaryBundle.clone(row.data),
|
||||
meta: row.meta
|
||||
});
|
||||
} else {
|
||||
return res.rows.map( row => row.meta );
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
async function getGroup (groupName, opts = {}) {
|
||||
|
||||
@@ -535,9 +347,6 @@ async function getGroup (groupName, opts = {}) {
|
||||
ORDER BY baseline_pid, monitor_pid
|
||||
`;
|
||||
|
||||
console.log(text);
|
||||
console.log(flatValues);
|
||||
|
||||
const res = await client.query(text, flatValues);
|
||||
if (!res.rows.length) {
|
||||
console.log("Comparison not found in database");
|
||||
@@ -567,12 +376,10 @@ module.exports = {
|
||||
get,
|
||||
save,
|
||||
getSample,
|
||||
saveSample,
|
||||
saveGroup,
|
||||
getGroup,
|
||||
remove,
|
||||
stats,
|
||||
// comparisonGeometricDifferences,
|
||||
asBundle,
|
||||
fromBundle
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user