diff --git a/majority-vote/.gitignore b/majority-vote/.gitignore new file mode 100644 index 0000000..3b72af0 --- /dev/null +++ b/majority-vote/.gitignore @@ -0,0 +1,2 @@ +.env +__pycache__ diff --git a/majority-vote/README.md b/majority-vote/README.md new file mode 100644 index 0000000..4bc4281 --- /dev/null +++ b/majority-vote/README.md @@ -0,0 +1,34 @@ +# Answer by Majority Vote + +The intention of this app is that for our collective answer to each question, we each run our individual answer and choose the one that has a majority. + +## Setup + +Create a `.env` file containing an OpenAI API key. Example: + +``` +OPENAI_API_KEY=sk-proj-thisisafakeapikey +``` + +Install requirements. +``` +pip install -r requirements.txt +``` + +## Adding your solution + +Make a python package like `sample`. It should have a function +like this: + +``` +def answer_question(question, schema): + ... +``` + +Include this function in the list `answer_functions` in `__main__.py`. + +## Running it + +``` +python -m majority_vote +``` diff --git a/majority-vote/majority_vote/__init__.py b/majority-vote/majority_vote/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/majority-vote/majority_vote/__main__.py b/majority-vote/majority_vote/__main__.py new file mode 100644 index 0000000..cb12da2 --- /dev/null +++ b/majority-vote/majority_vote/__main__.py @@ -0,0 +1,64 @@ +import json +import random +from collections import Counter +from typing import Callable, Optional + +import sample + +from dotenv import load_dotenv + + +def majorities(items): + # Count occurrences of each item + counts = Counter(items) + + # Find the maximum occurrence + max_count = max(counts.values()) + + # Extract items that have the maximum occurrence + result = [item for item, count in counts.items() if count == max_count] + + return result + + +def majority_vote(items): + not_none_items = [item for item in items if item is not None] + # Only return None if all items are None. + if len(not_none_items) == 0: + return None + else: + result = majorities(items) + # If there's a tie, return a random item from those that are tied. + return random.choice(result) + +load_dotenv() + +AnswerFunction = Callable[[str, str], Optional[str]] + +# TODO: Remove the sample answer_question function; add real functions. +answer_functions = [ sample.answer_question ] + +results = [] + +with open('questions.json', 'r') as json_file: + items = json.load(json_file) + + for item in items: + question = item["question"] + print(f"Processing question: {question}") + + answers = [ answer_question(question, item["schema"]) for answer_question in answer_functions ] + print(f"All answers: {answers}") + + answer = majority_vote(answers) + print(f"Chosen answer: {answer}") + print() + + results.append({ + "question": question, + "schema": item["schema"], + "answer": "n/a" if answer is None else answer + }) + +with open('results.json', 'w') as json_file: + json.dump(results, json_file, indent=4) \ No newline at end of file diff --git a/majority-vote/questions.json b/majority-vote/questions.json new file mode 100644 index 0000000..944b5ef --- /dev/null +++ b/majority-vote/questions.json @@ -0,0 +1,202 @@ +[ + { + "question": "How much did \"Accuray Incorporated\" spend on risk management in Q2 2022?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the CEO in the company \"Zegona Communications plc\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Global Medical REIT Inc.\" have a greater Debt-to-Equity ratio than \"Zegona Communications plc\" in Q2 2021?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"Accuray Incorporated\" have in the end of fiscal year 2021?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"Sandwell Aquatics Centre\" spend on R&D in Q2 2023?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the CFO in the company \"EMT\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Calyxt, Inc.\" have a greater Return on Assets (ROA) than \"Global Medical REIT Inc.\" in Q2 2023?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"OTC_UNCIF\" have in the end of fiscal year 2022?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"Accuray Incorporated\" spend on customer acquisition in Q2 2021?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the CEO in the company \"Accuray Incorporated\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Comet Holding AG\" have a greater Operating Margin than \"Ethernity Networks Ltd\" in Q2 2022?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2022?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"Ethernity Networks Ltd\" spend on R&D in Q2 2023?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the COO in the company \"Sandwell Aquatics Centre\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Calyxt, Inc.\" have a greater market capitalization than \"NICE\" in Q2 2022?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"Renishaw plc\" have in the end of fiscal year 2023?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"TD SYNNEX\" spend on R&D in Q2 2022?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the CFO in the company \"TD SYNNEX\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Eurocell PLC\" have a greater Return on Equity (ROE) than \"Strike Energy Limited\" in Q2 2022?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"OTC_UNCIF\" have in the end of fiscal year 2023?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"EMT\" spend on customer acquisition in Q2 2023?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the Board Chairman in the company \"Motus GI Holdings, Inc.\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Calyxt, Inc.\" have a greater Operating Margin than \"Banque Cantonale Vaudoise\" in Q2 2023?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"EMT\" have in the end of fiscal year 2023?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"Ethernity Networks Ltd\" spend on customer acquisition in Q2 2023?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the CFO in the company \"Ethernity Networks Ltd\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Canadian Banc Corp.\" have a greater Return on Assets (ROA) than \"VENUS METALS CORPORATION LIMITED\" in Q2 2021?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2023?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"Motus GI Holdings, Inc.\" spend on sustainability initiatives in Q2 2023?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the Board Chairman in the company \"Renishaw plc\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Canadian Banc Corp.\" have a greater Gross Profit Margin than \"Motus GI Holdings, Inc.\" in Q2 2022?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2021?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"Renishaw plc\" spend on risk management in Q2 2022?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the Board Chairman in the company \"TD SYNNEX\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Banque Cantonale Vaudoise\" have a greater Operating Margin than \"Zegona Communications plc\" in Q2 2021?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"Strike Energy Limited\" have in the end of fiscal year 2021?", + "schema": "number", + "answer": null + }, + { + "question": "How much did \"Ethernity Networks Ltd\" spend on customer acquisition in Q2 2023?", + "schema": "number", + "answer": null + }, + { + "question": "Who is the Chief Legal Officer in the company \"Nykredit\"?", + "schema": "name", + "answer": null + }, + { + "question": "Did \"Comet Holding AG\" have a greater Operating Margin than \"Calyxt, Inc.\" in Q2 2021?", + "schema": "boolean", + "answer": null + }, + { + "question": "How many stores did \"EMT\" have in the end of fiscal year 2022?", + "schema": "number", + "answer": null + } +] \ No newline at end of file diff --git a/majority-vote/requirements.txt b/majority-vote/requirements.txt new file mode 100644 index 0000000..2035bca --- /dev/null +++ b/majority-vote/requirements.txt @@ -0,0 +1 @@ +python_dotenv==1.0.1 diff --git a/majority-vote/results.json b/majority-vote/results.json new file mode 100644 index 0000000..1ad4e00 --- /dev/null +++ b/majority-vote/results.json @@ -0,0 +1,202 @@ +[ + { + "question": "How much did \"Accuray Incorporated\" spend on risk management in Q2 2022?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the CEO in the company \"Zegona Communications plc\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Global Medical REIT Inc.\" have a greater Debt-to-Equity ratio than \"Zegona Communications plc\" in Q2 2021?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"Accuray Incorporated\" have in the end of fiscal year 2021?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"Sandwell Aquatics Centre\" spend on R&D in Q2 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the CFO in the company \"EMT\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Calyxt, Inc.\" have a greater Return on Assets (ROA) than \"Global Medical REIT Inc.\" in Q2 2023?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"OTC_UNCIF\" have in the end of fiscal year 2022?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"Accuray Incorporated\" spend on customer acquisition in Q2 2021?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the CEO in the company \"Accuray Incorporated\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Comet Holding AG\" have a greater Operating Margin than \"Ethernity Networks Ltd\" in Q2 2022?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2022?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"Ethernity Networks Ltd\" spend on R&D in Q2 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the COO in the company \"Sandwell Aquatics Centre\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Calyxt, Inc.\" have a greater market capitalization than \"NICE\" in Q2 2022?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"Renishaw plc\" have in the end of fiscal year 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"TD SYNNEX\" spend on R&D in Q2 2022?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the CFO in the company \"TD SYNNEX\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Eurocell PLC\" have a greater Return on Equity (ROE) than \"Strike Energy Limited\" in Q2 2022?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"OTC_UNCIF\" have in the end of fiscal year 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"EMT\" spend on customer acquisition in Q2 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the Board Chairman in the company \"Motus GI Holdings, Inc.\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Calyxt, Inc.\" have a greater Operating Margin than \"Banque Cantonale Vaudoise\" in Q2 2023?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"EMT\" have in the end of fiscal year 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"Ethernity Networks Ltd\" spend on customer acquisition in Q2 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the CFO in the company \"Ethernity Networks Ltd\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Canadian Banc Corp.\" have a greater Return on Assets (ROA) than \"VENUS METALS CORPORATION LIMITED\" in Q2 2021?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"Motus GI Holdings, Inc.\" spend on sustainability initiatives in Q2 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the Board Chairman in the company \"Renishaw plc\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Canadian Banc Corp.\" have a greater Gross Profit Margin than \"Motus GI Holdings, Inc.\" in Q2 2022?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2021?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"Renishaw plc\" spend on risk management in Q2 2022?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the Board Chairman in the company \"TD SYNNEX\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Banque Cantonale Vaudoise\" have a greater Operating Margin than \"Zegona Communications plc\" in Q2 2021?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"Strike Energy Limited\" have in the end of fiscal year 2021?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "How much did \"Ethernity Networks Ltd\" spend on customer acquisition in Q2 2023?", + "schema": "number", + "answer": "n/a" + }, + { + "question": "Who is the Chief Legal Officer in the company \"Nykredit\"?", + "schema": "name", + "answer": "n/a" + }, + { + "question": "Did \"Comet Holding AG\" have a greater Operating Margin than \"Calyxt, Inc.\" in Q2 2021?", + "schema": "boolean", + "answer": "n/a" + }, + { + "question": "How many stores did \"EMT\" have in the end of fiscal year 2022?", + "schema": "number", + "answer": "n/a" + } +] \ No newline at end of file diff --git a/majority-vote/sample/__init__.py b/majority-vote/sample/__init__.py new file mode 100644 index 0000000..97233c7 --- /dev/null +++ b/majority-vote/sample/__init__.py @@ -0,0 +1,4 @@ +# This is a sample 'answer_question' function that always answers 'I have no answer'. + +def answer_question(question, schema): + return None \ No newline at end of file