Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheCorgi committed Mar 14, 2022
2 parents 53732ac + cbbae05 commit 4373194
Show file tree
Hide file tree
Showing 20 changed files with 314 additions and 7 deletions.
10 changes: 10 additions & 0 deletions api/app/graphql/queries/dynamic_routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Queries
class DynamicRoutes < Queries::BaseQuery
description 'Gets all routes from dynamic service'
type [Types::DynamicTopicType], null: false

def resolve
FetchDynamicRoutes.new.call
end
end
end
7 changes: 7 additions & 0 deletions api/app/graphql/types/dynamic_topic_option_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Types
class DynamicTopicOptionType < Types::BaseObject
description 'A type that represents a options for generating a dynamic question.'
field :name, String, null: false
field :route, String, null: false
end
end
7 changes: 7 additions & 0 deletions api/app/graphql/types/dynamic_topic_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Types
class DynamicTopicType < Types::BaseObject
description 'A type that represents a topic within dynamic service.'
field :name, String, null: false
field :options, [Types::DynamicTopicOptionType], null: false
end
end
1 change: 1 addition & 0 deletions api/app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ class QueryType < Types::BaseObject
field :tests, resolver: Queries::Tests
field :multiple_choice_questions, resolver: Queries::MultipleChoiceQuestions
field :questions, resolver: Queries::Questions
field :dynamic_routes, resolver: Queries::DynamicRoutes
end
end
16 changes: 16 additions & 0 deletions api/app/services/fetch_dynamic_routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class FetchDynamicRoutes
def initialize; end

def call(path = 'http://127.0.0.1:8000/api/')
data = HTTParty.get(path,
headers: { 'Content-Type' => 'application/json' })
.parsed_response
topics = []
data.each_key do |key|
question_routes = data[key.to_s]
questions_list = question_routes.map { |k, v| OpenStruct.new(name: k, route: v) }
topics << OpenStruct.new(name: key, options: questions_list)
end
topics
end
end
49 changes: 49 additions & 0 deletions api/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '3'

services:
api:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails db:setup && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
depends_on:
- db
links:
- db
networks:
- discretemath

db:
image: postgres:12-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 1234
ports:
- "5438:5432"
networks:
- discretemath

pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "5050:80"
depends_on:
- db
links:
- db
networks:
- discretemath

volumes:
database_postgres:

networks:
discretemath:
driver: bridge
Empty file modified api/entrypoint.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion client/src/data/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {getTest, getCourse, getCourseSession} from './services';
export {getTest, getCourse, getCourseSession, getRoutes} from './services';
35 changes: 35 additions & 0 deletions client/src/data/queries/DynamicRoutes/Routes.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const ROUTES_EXAMPLE_DATA = {
loading: false,
data: {
dynamicRoutes: [
{
name: 'demo',
options: [
{
name: 'graph_theory',
route: '/demo/graph-theory'
}
]
},
{
name: 'comp2804',
options: [
{
name: 'bitstrings-of-length',
route: '/comp2804/bitstrings-of-length'
},
{
name: 'set-theory-question',
route: '/comp2804/set-theory'
},
{
name: 'num-of-functions',
route: '/comp2804/num-of-functions'
}
]
}
]
}
};

export {ROUTES_EXAMPLE_DATA};
15 changes: 15 additions & 0 deletions client/src/data/queries/DynamicRoutes/Routes.query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {gql} from 'graphql-tag';

const ROUTES = gql`
query {
dynamicRoutes {
name
options {
name
route
}
}
}
`;

export {ROUTES};
2 changes: 2 additions & 0 deletions client/src/data/queries/DynamicRoutes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {ROUTES} from './Routes.query';
export {ROUTES_EXAMPLE_DATA} from './Routes.example';
1 change: 1 addition & 0 deletions client/src/data/queries/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export {TEST, TEST_EXAMPLE_DATA} from './Test';
export {COURSE, COURSE_EXAMPLE_DATA} from './Course';
export {COURSESESSION, COURSESESSION_EXAMPLE_DATA} from './CourseSession';
export {ROUTES, ROUTES_EXAMPLE_DATA} from './DynamicRoutes';
14 changes: 14 additions & 0 deletions client/src/data/services/getDynamicRoutes/Routes.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {query} from 'svelte-apollo';
import {ROUTES, ROUTES_EXAMPLE_DATA} from '../../queries';
import {readable} from 'svelte/store';

const getRoutes = () => {
// ENV VAR TO HIT API INSTEAD OF MOCK
if (process.env['USE_API'] === 'true') {
return query(ROUTES);
} else {
return readable(ROUTES_EXAMPLE_DATA, () => {});
}
};

export {getRoutes};
1 change: 1 addition & 0 deletions client/src/data/services/getDynamicRoutes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {getRoutes} from './Routes.service';
1 change: 1 addition & 0 deletions client/src/data/services/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export {getTest} from './getTest';
export {getCourse} from './getCourse';
export {getCourseSession} from './getCourseSession';
export {getRoutes} from './getDynamicRoutes';
Empty file.
69 changes: 69 additions & 0 deletions dynamic/generators/comp2804/binomial_expansion_coefficient/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import random


def generate_question():

a_coefficient = random.randint(2, 5)
b_coefficient = random.randint(3, 7)

x_exponent = random.randint(3, 8)
y_exponent = random.randint(5, 11)

n = random.randint(11, 15)

answer = f"-\genfrac(){{n}}{{y_exponent}}\cdot{a_coefficient}^{x_exponent}\cdot{b_coefficient}^{y_exponent}"

question_body = f"What is the coefficient of x^{x_exponent}y^{y_exponent} in the expansion of ({a_coefficient} - {b_coefficient}y)^{n}"

return {
"title": "bitstrings of length",
"body": question_body,
"body_format": "text",
"pseudocode": "",
"multiple_choice_answers": [
{
"body": answerchoice_1(
n, a_coefficient, b_coefficient, x_exponent, y_exponent
),
"body_format": "mathjax",
"correct": "false",
},
{
"body": answer,
"body_format": "mathjax",
"correct": "true",
},
{
"body": answerchoice_3(
n, a_coefficient, b_coefficient, x_exponent, y_exponent
),
"body_format": "mathjax",
"correct": "false",
},
{
"body": answerchoice_4(
n, a_coefficient, b_coefficient, x_exponent, y_exponent
),
"body_format": "mathjax",
"correct": "false",
},
],
}


def answerchoice_1(n, a_coefficient, b_coefficient, x_exponent, y_exponent):
return f"\genfrac(){{n}}{{y_exponent}}\cdot{a_coefficient}^{x_exponent}\cdot{b_coefficient}^{y_exponent}"

# answerchoice_2 purposefully omitted


def answerchoice_3(n, a_coefficient, b_coefficient, x_exponent, y_exponent):
return f"\genfrac(){{n}}{{y_exponent}}\cdot{a_coefficient}^{y_exponent}\cdot{b_coefficient}^{x_exponent}"


def answerchoice_4(n, a_coefficient, b_coefficient, x_exponent, y_exponent):
return f"-\genfrac(){{n}}{{y_exponent}}\cdot{a_coefficient}^{y_exponent}\cdot{b_coefficient}^{x_exponent}"


def call():
return generate_question()
Empty file.
71 changes: 71 additions & 0 deletions dynamic/generators/comp2804/let_m_and_n/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import random


def generate_question():
# generate required data
k = random.randint(2, 4) # value of k, m and n

# generate required content

question_body = (
"Let $m \geq "
+ str(k)
+ "$ and $n \geq "
+ str(k)
+ "$ be integers. What does $${{m}\choose{"
+ str(k)
+ "}} + {{n}\choose{"
+ str(k)
+ "}} + m\cdot n$$ count?"
)

answer_options = [
"The number of ways to choose a subset from a set consisting of $m + n$ elements.",
"The number of ways to choose an ordered pair of {} elements from a set consisting of $m + n$ elements.".format(
k
),
"The number of ways to choose a {}-element subset from a set consisting of $m + n$ elements.".format(
k
),
"None of the above.",
]
for answer in answer_options:
if "-element" in answer:
correct_answer = answer

# return generated question
return {
"title": "set_theory_question",
"body": question_body,
"bodyFormat": "text",
"pseudocode": "",
"multipleChoiceAnswers": [
{
"body": answer_options[0],
"bodyFormat": "mathjax",
"correct": "true",
},
{
"body": answer_options[1],
"bodyFormat": "mathjax",
"correct": "false",
},
{
"body": correct_answer,
"bodyFormat": "mathjax",
"correct": "false",
},
{
"body": answer_options[3],
"bodyFormat": "mathjax",
"correct": "false",
},
],
}


def call():
return generate_question()


print(call())
20 changes: 14 additions & 6 deletions dynamic/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import generators.comp2804.set_theory_question.main as set_theory_question_generator
import generators.comp2804.num_of_functions.main as num_of_functions_generator
import generators.comp2804.let_m_and_n.main as m_and_n_generator
import generators.comp2804.bitstrings_of_length.main as bitstrings_of_length_generator
import generators.comp2804.binomial_expansion_coefficient.main as binomial_expansion_coefficient_generator


import generators.comp2804.coefficient_of_term.main as coefficient_of_term_generator
import generators.comp2804.probability_of_choice.main as probability_of_choice_generator
Expand All @@ -26,11 +29,11 @@
"books_shelves_3": "/books_shelves/books_shelves_3",
},
"comp2804": {
"bitstrings-of-length": "/comp2804/bitstrings-of-length",
"binomial-expansion-coefficient": "/comp2804/binomial-expansion-coefficient",
"set-theory-question": "/comp2804/set-theory",
"num-of-functions": "/comp2804/num-of-functions",
"let-m-and-n-question": "/comp2804/let-m-and-n",
"bitstrings-of-length": "/comp2804/bitstrings-of-length",
"coefficient_of_term": "/comp2804/coefficient_of_term",
"probability_of_choice": "/comp2804/probability_of_choice",
},
Expand Down Expand Up @@ -83,11 +86,6 @@ async def generate_num_of_functions_question(
return num_of_functions_generator.call(lower_range, upper_range)


@router.get(routes["comp2804"]["bitstrings-of-length"])
async def bitstrings_of_length_question():
return bitstrings_of_length_generator.call()


@router.get(routes["comp2804"]["let-m-and-n-question"])
async def generate_m_and_n_question():
return m_and_n_generator.call()
Expand All @@ -97,6 +95,16 @@ async def generate_m_and_n_question():
async def generate_m_and_n_question():
return binomial_expansion_coefficient_generator.call()


@router.get(routes["comp2804"]["bitstrings-of-length"])
async def generate_bitstrings_of_length_question():
return bitstrings_of_length_generator.call()


@router.get(routes["comp2804"]["let-m-and-n-question"])
async def generate_m_and_n_question():
return m_and_n_generator.call()


@router.get(routes["comp2804"]["coefficient_of_term"])
async def coefficient_of_term_question():
Expand Down

0 comments on commit 4373194

Please sign in to comment.