mirror of
https://github.com/edcommonwealth/e2c-api.git
synced 2026-03-09 07:28:44 -07:00
add api implementation
This commit is contained in:
parent
e3dd39b5df
commit
5606f7fa69
114 changed files with 3202 additions and 0 deletions
0
app/assets/images/.keep
Normal file
0
app/assets/images/.keep
Normal file
10
app/assets/stylesheets/application.css
Normal file
10
app/assets/stylesheets/application.css
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* This is a manifest file that'll be compiled into application.css.
|
||||
*
|
||||
* With Propshaft, assets are served efficiently without preprocessing steps. You can still include
|
||||
* application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
|
||||
* cascading order, meaning styles declared later in the document or manifest will override earlier ones,
|
||||
* depending on specificity.
|
||||
*
|
||||
* Consider organizing styles into separate files for maintainability.
|
||||
*/
|
||||
4
app/controllers/application_controller.rb
Normal file
4
app/controllers/application_controller.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
||||
allow_browser versions: :modern
|
||||
end
|
||||
0
app/controllers/concerns/.keep
Normal file
0
app/controllers/concerns/.keep
Normal file
92
app/controllers/dashboard_controller.rb
Normal file
92
app/controllers/dashboard_controller.rb
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
class DashboardController < ApplicationController
|
||||
require 'httparty'
|
||||
require 'csv'
|
||||
require 'prawn'
|
||||
|
||||
def index
|
||||
@filters = fetch_filter_options
|
||||
|
||||
if params[:org_type]
|
||||
@selected = {
|
||||
org_type: params[:org_type],
|
||||
sy: params[:sy],
|
||||
grad_rate_type: params[:grad_rate_type],
|
||||
stu_grp: params[:stu_grp]
|
||||
}
|
||||
@data = fetch_filtered_data(@selected)
|
||||
else
|
||||
@selected = {}
|
||||
@data = []
|
||||
end
|
||||
end
|
||||
|
||||
def download_csv
|
||||
data = fetch_filtered_data(params)
|
||||
csv_string = CSV.generate(headers: true) do |csv|
|
||||
csv << data.first.keys if data.any?
|
||||
data.each { |row| csv << row.values }
|
||||
end
|
||||
send_data csv_string, filename: "graduation_stats.csv"
|
||||
end
|
||||
|
||||
def download_pdf
|
||||
data = fetch_filtered_data(params)
|
||||
pdf = Prawn::Document.new
|
||||
pdf.text "Graduation Stats Report", size: 14, align: :center
|
||||
pdf.move_down 10
|
||||
data.each_with_index do |row, i|
|
||||
pdf.text "#{i+1}. #{row.values.join(", ")}"
|
||||
end
|
||||
send_data pdf.render, filename: "graduation_stats.pdf", type: "application/pdf"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_filter_options
|
||||
response = HTTParty.get("https://educationtocareer.data.mass.gov/resource/n2xa-p822.json?$limit=1000", headers: headers)
|
||||
df = response.parsed_response
|
||||
{
|
||||
org_types: df.map { |x| x["org_type"] }.compact.uniq.sort,
|
||||
school_years: df.map { |x| x["sy"] }.compact.uniq.sort.reverse,
|
||||
rate_types: df.map { |x| x["grad_rate_type"] }.compact.uniq.sort,
|
||||
student_groups: df.map { |x| x["stu_grp"] }.compact.uniq.sort
|
||||
}
|
||||
end
|
||||
|
||||
def fetch_filtered_data(filters)
|
||||
where_clause = URI.encode_www_form_component("org_type='#{filters[:org_type]}' AND sy='#{filters[:sy]}' AND grad_rate_type='#{filters[:grad_rate_type]}' AND stu_grp='#{filters[:stu_grp]}'")
|
||||
url = "https://educationtocareer.data.mass.gov/resource/n2xa-p822.json?$where=#{where_clause}&$limit=50000"
|
||||
response = HTTParty.get(url, headers: headers)
|
||||
df = response.parsed_response
|
||||
|
||||
numeric_cols = %w[cohort_cnt grad_pct in_sch_pct non_grad_pct ged_pct drpout_pct exclud_pct]
|
||||
df.each do |row|
|
||||
numeric_cols.each { |col| row[col] = row[col].to_f if row[col] }
|
||||
end
|
||||
|
||||
name_col, code_col = case filters[:org_type]
|
||||
when "District" then ["dist_name", "dist_code"]
|
||||
when "School" then ["org_name", "org_code"]
|
||||
else ["org_name", "org_code"]
|
||||
end
|
||||
|
||||
df.map.with_index(1) do |row, idx|
|
||||
{
|
||||
"S. No." => idx,
|
||||
name_col => row[name_col],
|
||||
code_col => row[code_col],
|
||||
"# in Cohort" => row["cohort_cnt"],
|
||||
"% Graduated" => row["grad_pct"],
|
||||
"% Still in School" => row["in_sch_pct"],
|
||||
"% Non-Grad Completers" => row["non_grad_pct"],
|
||||
"% H.S. Equiv." => row["ged_pct"],
|
||||
"% Dropped Out" => row["drpout_pct"],
|
||||
"% Permanently Excluded" => row["exclud_pct"]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def headers
|
||||
{ "X-App-Token" => ENV["SOCRATA_APP_TOKEN"] }
|
||||
end
|
||||
end
|
||||
2
app/helpers/application_helper.rb
Normal file
2
app/helpers/application_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module ApplicationHelper
|
||||
end
|
||||
2
app/helpers/dashboard_helper.rb
Normal file
2
app/helpers/dashboard_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module DashboardHelper
|
||||
end
|
||||
3
app/javascript/application.js
Normal file
3
app/javascript/application.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
|
||||
import "@hotwired/turbo-rails"
|
||||
import "controllers"
|
||||
9
app/javascript/controllers/application.js
Normal file
9
app/javascript/controllers/application.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { Application } from "@hotwired/stimulus"
|
||||
|
||||
const application = Application.start()
|
||||
|
||||
// Configure Stimulus development experience
|
||||
application.debug = false
|
||||
window.Stimulus = application
|
||||
|
||||
export { application }
|
||||
7
app/javascript/controllers/hello_controller.js
Normal file
7
app/javascript/controllers/hello_controller.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
this.element.textContent = "Hello World!"
|
||||
}
|
||||
}
|
||||
4
app/javascript/controllers/index.js
Normal file
4
app/javascript/controllers/index.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// Import and register all your controllers from the importmap via controllers/**/*_controller
|
||||
import { application } from "controllers/application"
|
||||
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
|
||||
eagerLoadControllersFrom("controllers", application)
|
||||
7
app/jobs/application_job.rb
Normal file
7
app/jobs/application_job.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class ApplicationJob < ActiveJob::Base
|
||||
# Automatically retry jobs that encountered a deadlock
|
||||
# retry_on ActiveRecord::Deadlocked
|
||||
|
||||
# Most jobs are safe to ignore if the underlying records are no longer available
|
||||
# discard_on ActiveJob::DeserializationError
|
||||
end
|
||||
4
app/mailers/application_mailer.rb
Normal file
4
app/mailers/application_mailer.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: "from@example.com"
|
||||
layout "mailer"
|
||||
end
|
||||
3
app/models/application_record.rb
Normal file
3
app/models/application_record.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class ApplicationRecord < ActiveRecord::Base
|
||||
primary_abstract_class
|
||||
end
|
||||
0
app/models/concerns/.keep
Normal file
0
app/models/concerns/.keep
Normal file
38
app/views/dashboard/index.html.erb
Normal file
38
app/views/dashboard/index.html.erb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<%= form_with url: root_path, method: :get, local: true do |f| %>
|
||||
<div>
|
||||
<%= label_tag :org_type, "Report Type" %>
|
||||
<%= select_tag :org_type, options_for_select(@filters[:org_types], @selected[:org_type]) %>
|
||||
|
||||
<%= label_tag :sy, "School Year" %>
|
||||
<%= select_tag :sy, options_for_select(@filters[:school_years], @selected[:sy]) %>
|
||||
|
||||
<%= label_tag :grad_rate_type, "Graduation Rate Type" %>
|
||||
<%= select_tag :grad_rate_type, options_for_select(@filters[:rate_types], @selected[:grad_rate_type]) %>
|
||||
|
||||
<%= label_tag :stu_grp, "Student Group" %>
|
||||
<%= select_tag :stu_grp, options_for_select(@filters[:student_groups], @selected[:stu_grp]) %>
|
||||
|
||||
<%= submit_tag "Filter" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @data.present? %>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><% @data.first.keys.each do |key| %><th><%= key %></th><% end %></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @data.each do |row| %>
|
||||
<tr><% row.each { |_, value| %><td><%= value %></td><% } %></tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= link_to "Download CSV", download_csv_path(request.query_parameters), class: "button" %>
|
||||
<%= link_to "Download PDF", download_pdf_path(request.query_parameters), class: "button" %>
|
||||
<% else %>
|
||||
<% if @selected.present? %>
|
||||
<p>No data found for the selected combination.</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
28
app/views/layouts/application.html.erb
Normal file
28
app/views/layouts/application.html.erb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= content_for(:title) || "Myapp" %></title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<%= csrf_meta_tags %>
|
||||
<%= csp_meta_tag %>
|
||||
|
||||
<%= yield :head %>
|
||||
|
||||
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
|
||||
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
|
||||
|
||||
<link rel="icon" href="/icon.png" type="image/png">
|
||||
<link rel="icon" href="/icon.svg" type="image/svg+xml">
|
||||
<link rel="apple-touch-icon" href="/icon.png">
|
||||
|
||||
<%# Includes all stylesheet files in app/assets/stylesheets %>
|
||||
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
||||
<%= javascript_importmap_tags %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
||||
13
app/views/layouts/mailer.html.erb
Normal file
13
app/views/layouts/mailer.html.erb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<style>
|
||||
/* Email styles need to be inline */
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
||||
1
app/views/layouts/mailer.text.erb
Normal file
1
app/views/layouts/mailer.text.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
<%= yield %>
|
||||
22
app/views/pwa/manifest.json.erb
Normal file
22
app/views/pwa/manifest.json.erb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "Myapp",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icon.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
},
|
||||
{
|
||||
"src": "/icon.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
],
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"scope": "/",
|
||||
"description": "Myapp.",
|
||||
"theme_color": "red",
|
||||
"background_color": "red"
|
||||
}
|
||||
26
app/views/pwa/service-worker.js
Normal file
26
app/views/pwa/service-worker.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Add a service worker for processing Web Push notifications:
|
||||
//
|
||||
// self.addEventListener("push", async (event) => {
|
||||
// const { title, options } = await event.data.json()
|
||||
// event.waitUntil(self.registration.showNotification(title, options))
|
||||
// })
|
||||
//
|
||||
// self.addEventListener("notificationclick", function(event) {
|
||||
// event.notification.close()
|
||||
// event.waitUntil(
|
||||
// clients.matchAll({ type: "window" }).then((clientList) => {
|
||||
// for (let i = 0; i < clientList.length; i++) {
|
||||
// let client = clientList[i]
|
||||
// let clientPath = (new URL(client.url)).pathname
|
||||
//
|
||||
// if (clientPath == event.notification.data.path && "focus" in client) {
|
||||
// return client.focus()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (clients.openWindow) {
|
||||
// return clients.openWindow(event.notification.data.path)
|
||||
// }
|
||||
// })
|
||||
// )
|
||||
// })
|
||||
Loading…
Add table
Add a link
Reference in a new issue