mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:57:09 +00:00
Refactor project summaries to use database views
This commit is contained in:
@@ -7,15 +7,23 @@
|
||||
:loading="loading"
|
||||
>
|
||||
|
||||
<template v-slot:item.pid="props">
|
||||
<a :href="`/projects/${props.item.pid}`">{{props.value}}</a>
|
||||
<template v-slot:item.pid="{item, value}">
|
||||
<a :href="`/projects/${item.pid}`">{{value}}</a>
|
||||
</template>
|
||||
|
||||
<template v-slot:item.progress="props">
|
||||
{{ props.item.preplot_points ? (props.item.unique_shots/props.item.preplot_points*100).toFixed(1)+'%' : "" }}
|
||||
<v-progress-linear v-if="props.item.preplot_points"
|
||||
<template v-slot:item.shots="{item}">
|
||||
{{ item.total ? (item.prime + item.other) : "" }}
|
||||
</template>
|
||||
|
||||
<template v-slot:item.progress="{item}">
|
||||
{{
|
||||
item.total
|
||||
? ((1 - (item.remaining / item.total))*100).toFixed(1)+"%"
|
||||
: ""
|
||||
}}
|
||||
<v-progress-linear v-if="item.total"
|
||||
height="2"
|
||||
:value="(props.item.unique_shots/props.item.preplot_points*100)"
|
||||
:value="((1 - (item.remaining / item.total))*100)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -53,12 +61,16 @@ export default {
|
||||
text: "Lines"
|
||||
},
|
||||
{
|
||||
value: "sequences",
|
||||
value: "seq_final",
|
||||
text: "Sequences"
|
||||
},
|
||||
{
|
||||
value: "unique_shots",
|
||||
text: "Shots"
|
||||
value: "total",
|
||||
text: "Preplot points"
|
||||
},
|
||||
{
|
||||
value: "shots",
|
||||
text: "Shots acquired"
|
||||
},
|
||||
{
|
||||
value: "progress",
|
||||
|
||||
@@ -4,7 +4,7 @@ const { project} = require('../../../lib/db');
|
||||
module.exports = async function (req, res, next) {
|
||||
|
||||
try {
|
||||
res.status(200).send(await project.summary(req.params.project));
|
||||
res.status(200).send(await project.get(req.params.project));
|
||||
next();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
const { setSurvey } = require('../connection');
|
||||
|
||||
async function get (projectId, opts = {}) {
|
||||
const client = await setSurvey(projectId);
|
||||
|
||||
const text = `
|
||||
SELECT *
|
||||
FROM project_summary;
|
||||
`;
|
||||
|
||||
const res = await client.query(text);
|
||||
client.release();
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
module.exports = get;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
module.exports = {
|
||||
summary: require('./summary'),
|
||||
list: require('./list'),
|
||||
get: require('./get'),
|
||||
post: require('./post'),
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
const { setSurvey } = require('../connection');
|
||||
|
||||
|
||||
async function summary (projectId, opts = {}) {
|
||||
const client = await setSurvey(projectId);
|
||||
|
||||
|
||||
const sortFields = [
|
||||
"pid", "name", "lines", "sequences", "unique_shots",
|
||||
"total_shots", "info"
|
||||
];
|
||||
const sortKey = opts.sortBy && sortFields.includes(opts.sortBy) && opts.sortBy || "pid";
|
||||
const sortDir = opts.sortDesc == "true" ? "DESC" : "ASC";
|
||||
const offset = Math.abs((opts.page-1)*opts.itemsPerPage) || 0;
|
||||
const limit = Math.abs(Number(opts.itemsPerPage)) || null;
|
||||
|
||||
// FIXME Make this into a PostgreSQL stored procedure
|
||||
const text = `
|
||||
SELECT * FROM projects,
|
||||
(SELECT
|
||||
(SELECT COUNT(DISTINCT line) FROM preplot_lines WHERE class='V') AS lines,
|
||||
(SELECT COUNT(DISTINCT sequence) FROM final_lines) AS sequences,
|
||||
(SELECT COUNT(*) from (
|
||||
SELECT DISTINCT fl.line, fs.point
|
||||
FROM final_lines fl INNER JOIN final_shots fs USING (sequence)) AS t) AS unique_shots,
|
||||
(SELECT COUNT(*) FROM final_shots) AS total_shots,
|
||||
(SELECT COUNT(*) FROM preplot_points WHERE class = 'S') AS preplot_points) info
|
||||
WHERE current_setting('search_path') LIKE projects.schema||'%';
|
||||
`;
|
||||
|
||||
const res = await client.query(text);
|
||||
client.release();
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
|
||||
module.exports = summary;
|
||||
Reference in New Issue
Block a user