FORM_COUNT = 5
GENERATE_COUNT = 10
GENERATE_THRESHHOLD = 10
-BACKUP_TIME = 2
+
+BACKUP_TIME = 2#h
BACKUP_COUNT = 5
+RECCUR_WAIT = 10#s
+RECCUR_DEPTH = 5
+
app = Flask(__name__)
auth = HTTPBasicAuth()
f"UPDATE master SET counter = counter + 1 WHERE key = 'u{key}'"
)
+ connection.commit()
+
return key
# get FORM_COUNT questions from the database and increment the tracker
-def get_questions(key: str):
+def get_questions(key: str, depth = 1):
with sqlite3.connect(f"{app.root_path}/database.db") as connection:
cursor = connection.cursor()
"""
SELECT * FROM u{key}
WHERE answer IS NULL
ORDER BY
- created DESC;
+ created ASC;
"""
)
names = [description[0] for description in cursor.description]
- result = [dict(zip(names, selection.fetchone())) for _ in range(FORM_COUNT)]
+ result = []
+ for _ in range(FORM_COUNT):
+ row = selection.fetchone()
+ if row is not None:
+ question = dict(zip(names, row))
+ result.append(question)
+ elif depth < RECCUR_DEPTH:
+ logger.error(f"User {key} ran out of questions. Waiting and reccuring")
+
+ dispatch = True
+ for th in threading.enumerate():
+ if th.name == f"g{key}":
+ dispatch = False
+ logger.warning(f"Generator {key} attempted to dispatch, but was already running")
+
+ if dispatch:
+ logger.info(f"Generator {key} re-dispatched within recursion (depth {depth})")
+ threading.Thread(target=generate_questions, args=(key,), name=f"g{key}").start()
+
+ time.sleep(RECCUR_WAIT)
+ result = get_questions(key, depth+1)
+ else:
+ logger.error(f"User {key} maximum depth reached")
+ quit()
return result
"""
for th in threading.enumerate():
if th.name == f"g{key}":
- logger.warn(f"Generator {key} attempted to dispatch, but was already running")
+ logger.warning(f"Generator {key} attempted to dispatch, but was already running")
return
logger.info(f"Generator {key} dispatched")
# add GENERATE_COUNT questions to the database for key x based off the previous questions
def generate_questions(key: str):
start = time.time()
- time.sleep(10)
+
+ with sqlite3.connect(f"{app.root_path}/database.db") as connection:
+ cursor = connection.cursor()
+ selection = cursor.execute(f"""
+ SELECT * FROM u{key}
+ WHERE answer IS NOT NULL
+ ORDER BY created DESC;
+ """)
+
+ names = [description[0] for description in cursor.description]
+ data = [dict(zip(names, selection.fetchone())) for _ in range(FORM_COUNT)]
+ learn = [{"question":x["question"], "answer":x[f"option_{x['answer']}"]} for x in data]
+
+ prompt = f"""
+ <system>
+ Here are a selection of questions and their respecive aswers from a participant answering a survey.
+ Please produce {GENERATE_COUNT} more questions that lead off of the given answers to produce a more
+ personal experiance.
+ </system>
+ """
# get the generic pre-written questions
with open("generic.json","r") as f:
if table[0][0] == "u":
cursor.execute(f"DROP TABLE {table[0]};")
+ connection.commit()
return "", 200
scheduler = BackgroundScheduler()