/
backend.py
128 lines (100 loc) · 3.24 KB
/
backend.py
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
# Dictionary of questions
# Class(?)es(?) for
# body of get_question()
# body of put_answer()
#
class Question:
def __init__(self, text, options):
self.text = text
self.options = options
def get_text(self):
return self.text
def get_options(self):
return list(self.options.keys())
def next_step(self, option):
# get the next question ID
next = self.options[option]
return next
def get_info(self):
return (self.get_text(), self.get_options())
questions = {
1: Question("Has the project a fixed end date", {"Yes": 2, "(No)": None}),
2: Question(
"Is there a single developer/maintainer of the project?",
{"Yes": 3, "(No)": None},
),
3: Question(
"Is there secured funding to cover ongoing support", {"(Yes)": None, "No": 4}
),
4: Question(
"Do you hope to secure funding to cover ongoing support?",
{"Yes": 5, "(No)": None},
),
5: Question(
"What type of ongoing maintenence do you intend to provide?",
{
"(Answer queries)": None,
"(Implement requested features)": None,
"Review merge requests": None,
"(Curate issues page)": None,
},
),
}
# question_returned = ("question text", question[1].keys())
# example data structure containing questions
# format is {id: question}
# example = {
# 1: Question("example text 1", {"option 1 ": 2, "option 2": 3}),
# 2: Question("example text 2", {"option 1 ": 2, "option 2": 3}),
# 3: Question("example text 3", {"option 1 ": 2, "option 2": 3}),
# }
answer_sheet = []
# questions = example
current_question = 1
def get_question():
"""Returns:
the text of a question,
an iterable of options, and
the next steps for each option."""
global questions
if current_question is None:
return False, (None, None)
q = questions[current_question]
if current_question == None:
status = False
else:
status = True
return status, q.get_info()
# should return the response and add
# the question/answer to the answer sheet
def put_answer(question_text, chosen_option):
"""Returns status:
Error, etc.
More questions True/False"""
global current_question
answer_sheet.append((current_question, chosen_option))
q = questions[current_question]
current_question = q.next_step(chosen_option)
if current_question == None:
status = False
else:
status = True
return status
def get_badge():
return get_badges()
def get_badges():
md_code = "[![Twilight Date](https://github.com/elichad/software-twilight/blob/main/twilight_date_example.svg)](https://github.com/elichad/software-twilight)\n[![Twilight Date](https://github.com/elichad/software-twilight/blob/main/twilight_plan_example.svg)](https://github.com/elichad/software-twilight)"
return md_code
def print_answers(responses):
"""Returns a string:
Question1: Answer1
Question2: Answer2"""
answers = []
for item in responses:
question, answer = item
answers.append(str(question) + ": " + str(answer))
return "".join(answers)
def reset():
global current_question
current_question = 1
# def select_badge():