Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from calblueprint/form-branch
Browse files Browse the repository at this point in the history
form-branch
  • Loading branch information
micahtyong authored Oct 30, 2021
2 parents 4d7fd75 + 16b144d commit ae7136d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__/
testing/
Examples.ipynb
errorLog.csv
.ipynb_checkpoints/
105 changes: 87 additions & 18 deletions d8error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
import json
import os.path
import csv
import ipywidgets as widgets

class Announce:
"""error index, serves as an id on the csv file"""
eindex = 0

def __init__(self, etype, value):
self.eindex = Announce.eindex
Announce.eindex += 1
self.etype = etype
self.value = value
self.feedbackRating = 0
self.feedbackMSG = ""
self.errorname = str(etype().__class__.__name__)
with open("errorConfig.json", "r") as f:
diction = json.load(f)
Expand All @@ -22,24 +30,33 @@ def __init__(self, etype, value):
if (key in str(value)):
prewrittenMessge = True
self.print = prewrittenMessge


def writeRow(file):
"""saves errors to errorLog.csv"""
fieldnames = ['index', 'errorType', 'errorMSG', 'feedbackRating', 'feedbackMSG']
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writerow({"index": self.eindex,
"errorType": self.errorname,
"errorMSG": str(self.value),
"feedbackRating": self.feedbackRating,
"feedbackMSG": self.feedbackMSG})

if not os.path.isfile("errorLog.csv"):
with open('errorLog.csv', 'w', newline='') as f:

fieldnames = ['errorType', 'errorMSG']
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writerow({"errorType": self.errorname,"errorMSG": str(value)})
writeRow(f)
else:
if Announce.eindex == 1:
with open("errorLog.csv", 'r') as f:
for row in csv.reader(f):
self.eindex = int(row[0])
self.eindex += 1
Announce.eindex = self.eindex + 1
with open('errorLog.csv', 'a', newline='') as f:

fieldnames = ['errorType', 'errorMSG']
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writerow({"errorType": self.errorname,"errorMSG": str(value)})

writeRow(f)

def tips(self):
etype = self.etype
value = self.value

with open("errorConfig.json", "r") as f:
diction = json.load(f)
exceptionClass = diction.get(self.errorname)
Expand All @@ -65,7 +82,65 @@ def title(self):
def default(self):
display(Markdown("It seems we have a "+self.errorname+ ". " +self.errorname+ "s are usually because of:"))
def feedback(self):
display(Markdown("Please fill out this quick survey to help us improve the the error feedback [Data 8 Error Feedback Survey](https://forms.gle/6UZQjwZmAxVDMsBR6)"))
def overwriteRow():
"""rewrites the feedbackRating & feedbackMSG columns on errorLog.csv"""
with open("errorLog.csv", 'r') as f:
reader = csv.reader(f, delimiter=',')
lines = []
for line in reader:
if line[0] == str(self.eindex):
line[3] = self.feedbackRating
line[4] = self.feedbackMSG
lines.append(line)
with open("errorLog.csv", 'w', newline='') as f:
writer = csv.writer(f, delimiter=',')
writer.writerows(lines)

"""create & label a dropdown menu"""
dropdown_label = widgets.Label(value="Was the message you saw useful?")
dropdown = widgets.Dropdown(options=[('', 0),
('Extremely useful', 5),
('Very useful', 4),
('Somewhat useful', 3),
('Slightly useful', 2),
('Not at all useful', 1)],
value=0)
def handle_slider_change(change):
"""on change: rewrites the feedbackRating in the CSV"""
self.feedbackRating = dropdown.value
overwriteRow()
dropdown.observe(handle_slider_change)

"""create & label a textbox"""
textbox_label = widgets.Label(value="Any other feedback?")
textbox = widgets.Text(value="",
placeholder="Press enter to submit.",
layout=widgets.Layout(width='50%', margin='0px 8px 0px 0px', padding='0px'))
def submit_text(t):
"""on textbox submit: remove other fields and replace with a thank you message"""
self.feedbackMSG = t.value
accordion.children = [widgets.Label(value="Thank you for your feedback!")]
overwriteRow()
textbox.on_submit(submit_text)

"""create a submit button for the textbox"""
submit_button = widgets.Button(description="Submit",
layout=widgets.Layout(width='10%', min_width='80px'))
def on_btn_click(b):
"""on button click: submits textbox and replaces other fields with a thank you message"""
submit_text(textbox)
submit_button.on_click(on_btn_click)

"""bundle together widgets for a cleaner output"""
dropdownBox = widgets.VBox([dropdown_label, dropdown])
submitBox = widgets.HBox([textbox, submit_button])
submitBox.layout.align_items = 'center'
textboxBox = widgets.VBox([textbox_label, submitBox])
output = widgets.VBox([dropdownBox, textboxBox])
accordion = widgets.Accordion([output])
accordion.set_title(0, ' Feedback Form')

display(accordion)

def test_exception(self, etype, value, tb, tb_offset=None):
try:
Expand All @@ -81,9 +156,3 @@ def test_exception(self, etype, value, tb, tb_offset=None):
self.showtraceback((etype, value, tb), tb_offset=tb_offset)

get_ipython().set_custom_exc((Exception,), test_exception)

if not os.path.isfile("errorLog.csv"):
with open('errorLog.csv', 'w', newline='') as f:
fieldnames = ['errorType', 'errorMSG']
writer = csv.DictWriter(f, fieldnames=fieldnames)
#s

0 comments on commit ae7136d

Please sign in to comment.