Skip to content

Commit

Permalink
objtime
Browse files Browse the repository at this point in the history
  • Loading branch information
terrywbrady committed May 1, 2024
1 parent 5188efb commit 6369551
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src-admintool/config/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ collections_by_time_count:
- year by year since the Merritt system was established
- day by day for the past week
- week by week for the last 4 weeks
collections_by_time_count_obj:
link-title: Objects Added by Date
breadcrumb: bp_ingest
class: CollectionObjectsByTimeQuery
category: collections/time
description: |
This report shows the count of objects added to each Merritt collection.
This report includes both system and producer files.
Based on the interval parameter, the report may show Counts
- year by year since the Merritt system was established
- day by day for the past week
- week by week for the last 4 weeks
collections_by_time_size:
link-title: Bytes Added by Date
breadcrumb: bp_ingest
Expand Down
125 changes: 125 additions & 0 deletions src-admintool/queries/collections_obj_by_time_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# frozen_string_literal: true

require 'date'

# Query class - see config/reports.yml for description
class CollectionObjectsByTimeQuery < AdminQuery
def initialize(query_factory, path, myparams)
super(query_factory, path, myparams)
@interval = get_param('interval', '')
@interval = @interval == 'years' || @interval == 'days' || @interval == 'weeks' ? @interval : 'years'
@ranges = []

if @interval == 'days'
@end = Date.today + 1
@start = @end - 7
rstart = @start
while rstart < @end
@ranges.push([rstart, rstart + 1])
rstart += 1
end
elsif @interval == 'weeks'
@end = Date.today - Date.today.cwday + 7
@start = @end - 28
rstart = @start
while rstart < @end
@ranges.push([rstart, rstart + 7])
rstart += 7
end
else
@end = Date.today.next_year.prev_month(Date.today.month - 1) - Date.today.mday + 1
@start = Date.new(2013, 0o1, 0o1)
rstart = @start
while rstart < @end
@ranges.push([rstart, rstart.next_year])
rstart = rstart.next_year
end
end
@headers = ['Group', 'Collection Id', 'Collection Name']
@types = %w[ogroup colllist name]
@ranges.each do |range|
@headers.push(range[0])
@types.push('dataint')
end
@headers.push('Total')
@types.push('dataint')
end

def get_headers(_results)
@headers
end

def get_types(_results)
@types
end

def get_filter_col
2
end

def get_group_col
0
end

def get_title
"Collection Objects Over Time (#{@start} - #{@end})"
end

def get_sql
%{
select distinct
oc.ogroup as ogroup,
oc.inv_collection_id as ocid,
oc.collection_name as ocname,
(
select
count(inv_object_id)
from
inv.inv_collections_inv_objects icio
inner join inv.inv_objects o
on o.id = icio.inv_object_id
where
oc.inv_collection_id = icio.inv_collection_id
and
o.created >= ?
and
o.created < ?
) as sumval
from
owner_collections oc
group by
ogroup,
ocid,
ocname
order by
ogroup,
ocid,
ocname
}
end

def get_query_params(pstart, pend)
[
pstart, pend
]
end

def run_query_sql
stmt = @client.prepare(get_sql)
params = get_query_params(@start, @end)

results = stmt.execute(*params)
types = get_types(results)
combined_data = get_result_data(results, types)

@ranges.each do |range|
params = get_query_params(range[0], range[1])
results = stmt.execute(*params)
data = get_result_data(results, types)
data.each_with_index do |r, i|
combined_data[i].insert(-2, r[3])
end
end
format_result_json(types, combined_data, get_headers(results))
end
end
1 change: 1 addition & 0 deletions src-admintool/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ <h3>Ingest Counts</h3>
<ul>
<li class="graph"><a class="json" href="{{ADMINTOOL_HOME}}?path=collections_by_time_count_producer">Producer Files Added by Date (All time)</a></li>
<li class="graph"><a class="json" href="{{ADMINTOOL_HOME}}?path=collections_by_time_count">Files Added by Date (All time)</a></li>
<li class="graph"><a class="json" href="{{ADMINTOOL_HOME}}?path=collections_by_time_count_obj">Objects Added by Date (All time)</a></li>
<li class="graph"><a class="json" href="{{ADMINTOOL_HOME}}?path=collections_by_time_size">File Size Added by Date (All time)</a></li>
<li class="graph"><a class="json" href="{{ADMINTOOL_HOME}}?path=collections_by_time_size_cumulative">Cumulative File Size Added by Date (All time)</a></li>
<li class="graph"><a class="json" href="{{ADMINTOOL_HOME}}?path=collections_by_time_count_producer&interval=days">Producer Files Added by Date (Last week)</a></li>
Expand Down

0 comments on commit 6369551

Please sign in to comment.