Skip to content

Instantly share code, notes, and snippets.

@hawkrives
Last active May 15, 2024 17:05
Show Gist options
  • Save hawkrives/4855616dbda70f7708839ac07cfcf246 to your computer and use it in GitHub Desktop.
Save hawkrives/4855616dbda70f7708839ac07cfcf246 to your computer and use it in GitHub Desktop.
test carbide
import {examine, expandStudent} from '@gobbldygook/core'
import yaml from 'js-yaml'
import {padStart} from 'lodash/padStart'
import * as school from '@gobbldygook/school-stolaf'
function find_details_subdir(clbid) {
let str_clbid = padStart(clbid, 10, '0')
let n_thousand = Math.floor(clbid / 1000)
let thousands_subdir = padStart(n_thousand * 1000, 5, '0')
return thousands_subdir + '/' + str_clbid
}
function loadCourse(clbid) { ///Load the course… by requesting it from github! :D
return fetch(`https://raw.githubusercontent.com/StoDevX/course-data/master/courses/${find_details_subdir(clbid)}.json`).then(r => r.json())
}
function loadArea({name, revision, type}) { ///This variant won't actually work for most people, but it'd do for a demo.
let url
if (name === 'Computer Science') {
url = 'https://raw.githubusercontent.com/hawkrives/gobbldygook-area-data/master/majors/computer-science.yaml'
}
else if (name === 'Asian Studies') {
url = 'https://raw.githubusercontent.com/hawkrives/gobbldygook-area-data/master/majors/asian-studies.yaml'
}
return fetch(url).then(r => r.text()).then(t => yaml.safeLoad(t))
}
function prettify(school, results) {
// make the results pretty
return JSON.stringify(results)
}
async function main(student_file) {
const student = {name: 'Hawken Rives'}
// We start with a basic student, and flesh it out with the referenced data
const loaded = await expandStudent(student, loadCourse, loadArea)
// Then we check it
const results = await examine(loaded)
// and finally we show the results
console.log(prettify(school, results))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment