Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Query for validation statistics to add refMatch field #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions validation-tool-backend/src/auth/roles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { ROLES_KEY } from './roles.decorator';

@Injectable()
export class RolesGuard implements CanActivate {
constructor(private reflector: Reflector) {}
constructor(private reflector: Reflector) { }

canActivate(context: ExecutionContext): boolean {
const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [
context.getHandler(), // try to get @Roles from invoked Controller method
context.getClass() // fallback: get @Roles from Controller class
]);
//console.log(`Required Roles = ${requiredRoles}`);

if (!requiredRoles) {
return true;
}
Expand Down
40 changes: 20 additions & 20 deletions validation-tool-backend/src/review/review.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,26 +310,26 @@ export class ReviewService {
const pool = await this.databaseService.getConnection();

const result = await pool.request().query(`
WITH u AS (
SELECT run_id r, 'n_mention_candidates' k, count(distinct(mention_candidate)) v FROM dyad GROUP BY run_id
UNION
SELECT run_id r, 'n_publications' k, count(distinct(external_id)) v FROM publication GROUP BY run_id
UNION
SELECT d.run_id r, 'n_datasets' k, count(distinct(da.parent_alias_id)) v FROM dyad d JOIN dataset_alias da ON d.dataset_alias_id = da.id GROUP BY d.run_id
UNION
SELECT run_id r, 'n_dyads' k, sum(n) FROM (SELECT run_id, 1 n FROM dyad GROUP BY run_id, publication_id, mention_candidate) x GROUP BY run_id
UNION
SELECT run_id r, 'n_snippets_total' k, count(*) v FROM dyad GROUP BY run_id
UNION
SELECT run_id r, 'n_snippets_nonempty' k, count(*) v FROM dyad WHERE snippet IS NOT NULL AND snippet != '' GROUP BY run_id
UNION
SELECT run_id r, 'n_total_dyads' k, count(*) v FROM dyad_model GROUP BY run_id
UNION
SELECT run_id r, 'n_undetected_datasets' k, count(*) v FROM dyad WHERE alias_id IS NULL GROUP BY run_id
)
SELECT * FROM u
WHERE r = ${run_id}
ORDER BY r;
declare @run_id bigint = ${run_id}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from Tina's response, that the refmatch should count unique publications, i gather that the following should be the query:
declare @run_id bigint = ${run_id}
declare @refmatch_id bigint
select @refmatch_id=id from model where name='refmatch'
;
with valid_datasets as (
SELECT da.parent_alias_id
FROM snippet_validation sv
join dyad d on d.id=sv.dyad_id
JOIN dataset_alias da ON d.dataset_alias_id = da.id
where sv.run_id = @run_id and sv.agency_dataset_identified = 1
union
SELECT da.parent_alias_id
FROM dyad_model dm
join dyad d on d.id=dm.dyad_id
JOIN dataset_alias da ON d.dataset_alias_id = da.id and d.run_id = @run_id
where dm.model_id=@refmatch_id
)
SELECT 'n_datasets' k, count(distinct parent_alias_id) v FROM valid_datasets
UNION
SELECT 'n_refmatch' k, count(distinct d.publication_id) v
FROM dyad_model dm join dyad d on d.id = dm.dyad_id
WHERE dm.model_id=@refmatch_id and dm.run_id=@run_id

declare @refmatch_id bigint
select @refmatch_id=id from model where name='refmatch'
;
with valid_datasets as (
SELECT da.parent_alias_id
FROM snippet_validation sv
join dyad d on d.id=sv.dyad_id
JOIN dataset_alias da ON d.dataset_alias_id = da.id
where sv.run_id = @run_id and sv.agency_dataset_identified = 1
union
SELECT da.parent_alias_id
FROM dyad_model dm
join dyad d on d.id=dm.dyad_id
JOIN dataset_alias da ON d.dataset_alias_id = da.id and d.run_id = @run_id
where dm.model_id=@refmatch_id
)
SELECT 'n_datasets' k, count(distinct parent_alias_id) v FROM valid_datasets
UNION
SELECT 'n_refmatch' k, count(distinct dm.dyad_id) v FROM dyad_model dm where dm.model_id=@refmatch_id and run_id=@run_id
`);
if (result?.recordset.length) {
result.recordset.forEach((rc) => {
Expand Down