-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstats.html.erb
More file actions
128 lines (123 loc) · 4.72 KB
/
stats.html.erb
File metadata and controls
128 lines (123 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
layout: page
---
<% @title = "Collection Statistics & Insights" %>
<% stats = collection_stats %>
<% categories = all_categories(tonic_collection) %>
<h1><%= @title %></h1>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mt-4 mb-8">
<div class="card">
<div class="card-body text-center">
<div class="text-3xl font-bold text-gray-800"><%= stats[:total_items] %></div>
<div class="text-sm text-gray-600">Total items</div>
</div>
</div>
<div class="card">
<div class="card-body text-center">
<div class="text-3xl font-bold text-gray-800"><%= stats[:unique_fields] %></div>
<div class="text-sm text-gray-600">Unique attributes</div>
</div>
</div>
<div class="card">
<div class="card-body text-center">
<div class="text-3xl font-bold text-gray-800"><%= categories.size %></div>
<div class="text-sm text-gray-600">Categories</div>
</div>
</div>
</div>
<h2>Attributes Analysis</h2>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-4 mb-8">
<% stats[:field_stats].each do |field, field_data| %>
<% field_stats = field_data[:stats] %>
<div class="card">
<div class="card-header">
<h3>
<%= field.titleize %>
<span class="inline-block px-2 py-1 text-xs rounded-full bg-gray-200 text-gray-800">
<%= field_data[:type] %>
</span>
<span class="text-gray-600 text-sm">
<%= pluralize field_stats[:total_entries], 'entry' %>
</span>
</h3>
</div>
<div class="card-body text-sm mb-2">
<% case field_data[:type] %>
<% when 'categorical' %>
<div class="mb-2">
<strong>Unique values</strong> <%= field_stats[:unique_values] %>
</div>
<% if field_stats[:most_common] %>
<div>
<strong>Most common</strong>
<ul class="mt-2">
<% field_stats[:most_common].first(3).each do |value, count| %>
<li><%= value %> (<%= count %>)</li>
<% end %>
</ul>
</div>
<% end %>
<% when 'numeric' %>
<div class="grid grid-cols-2 gap-2">
<div><strong>Min</strong> <%= field_stats[:min] %></div>
<div><strong>Max</strong> <%= field_stats[:max] %></div>
<div><strong>Average</strong> <%= field_stats[:average] %></div>
<div><strong>Unique</strong> <%= field_stats[:unique_values] %></div>
</div>
<% when 'array' %>
<div class="mb-2">
<strong>Unique values</strong> <%= field_stats[:total_unique_values] %>
</div>
<div class="mb-2">
<strong>Avg items per entry</strong> <%= field_stats[:avg_items_per_entry] %>
</div>
<% if field_stats[:most_common] %>
<div>
<strong>Most common</strong>
<div class="mt-2">
<%= render_tags(field_stats[:most_common].keys.first(5)) %>
</div>
</div>
<% end %>
<% when 'date' %>
<div><strong>Date range</strong></div>
<div><%= field_stats[:earliest] %> to <%= field_stats[:latest] %></div>
<div class="mt-2"><strong>Unique dates</strong> <%= field_stats[:unique_dates] %></div>
<% when 'boolean' %>
<div><strong>True</strong> <%= field_stats[:true_count] %> (<%= field_stats[:true_percentage] %>%)</div>
<div><strong>False</strong> <%= field_stats[:false_count] %> (<%= 100 - field_stats[:true_percentage] %>%)</div>
<% else %>
<div><strong>Unique values</strong> <%= field_stats[:unique_values] %></div>
<% if field_stats[:most_common] %>
<div class="mt-2">
<strong>Most common</strong>
<ul>
<% field_stats[:most_common].first(3).each do |value, count| %>
<% if is_hash?(value) %>
<li><%= render_hash(value) %></li>
<% else %>
<li><%= strip_truncate(value.to_s, 60) %> (<%= count %>)</li>
<% end %>
<% end %>
</ul>
</div>
<% end %>
<% end %>
</div>
</div>
<% end %>
</div>
<% if categories.any? %>
<h2>Category Breakdown</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mt-4 mb-8">
<% categories.each do |category| %>
<% items_count = items_for_category(category).size %>
<div class="card flex justify-between items-center p-4">
<a href="<%= category_page_url(category) %>"><%= category %></a>
<div class="text-sm text-gray-600">
<%= pluralize items_count, 'item' %>
</div>
</div>
<% end %>
</div>
<% end %>