-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start implementating genetic algorithm
- Loading branch information
1 parent
b1daf25
commit 5c6369f
Showing
8 changed files
with
185 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sys | ||
import random | ||
from typing import List | ||
from gatorgrouper.utils import group_genetic | ||
|
||
|
||
def swap(grouping): | ||
# print("MUTATION") | ||
group_count = len(grouping) | ||
# print("TOTAL GROUPS: {}".format(group_count)) | ||
# print("BEFORE: {}".format(grouping)) | ||
first, second = random.sample(range(len(grouping)), 2) | ||
first_index = random.randrange(len(grouping[first])) | ||
second_index = random.randrange(len(grouping[second])) | ||
# print("swapping student {} in group {} with student {} in group {}".format(first_index, first, second_index, second)) | ||
temp = grouping[second][second_index] | ||
grouping[second][second_index] = grouping[first][first_index] | ||
grouping[second][second_index] = temp | ||
# grouping[first][first_index], grouping[second][second_index] = grouping[second][second_index], grouping[first][first_index] | ||
# print("AFTER: {}".format(grouping)) | ||
|
||
return grouping | ||
|
||
|
||
def multi_swap(grouping): | ||
num_swaps = random.randrange(1, 6) | ||
for _ in range(num_swaps): | ||
grouping = swap(grouping) | ||
return grouping | ||
|
||
|
||
def get(): | ||
return [swap, multi_swap] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Integrate GatorGrouper with Google Sheets.""" | ||
|
||
import csv | ||
import math | ||
import logging | ||
import gspread | ||
import pandas as pd | ||
from oauth2client.service_account import ServiceAccountCredentials | ||
|
||
from gatorgrouper.utils import group_genetic | ||
from gatorgrouper.utils import constants | ||
|
||
|
||
EMAIL_COL = None | ||
PREFERENCES_COL = None | ||
SKILLS_COLS = set() | ||
|
||
STUDENTS = None | ||
GROUPING_SIZE = None | ||
|
||
def get(group_size): | ||
"""Retrieve data from Google Sheets and write to a CSV file.""" | ||
|
||
global EMAIL_COL | ||
global PREFERENCES_COL | ||
global SKILLS_COLS | ||
|
||
# formatted_records = list() | ||
# for entry in records: | ||
# formatted_entry = list() | ||
# for index, (question, response) in enumerate(entry.items()): | ||
# if question == 'Email Address': | ||
# EMAIL_COL = index - 1 # subtracting one because timestamp column not collected | ||
# formatted_entry.append(response) | ||
# elif "prefer" in question: | ||
# PREFERENCES_COL = index - 1 | ||
# formatted_entry.append(response) | ||
# elif "skill" in question: | ||
# SKILLS_COLS.add(index - 1) | ||
# formatted_entry.append(response) | ||
# formatted_records.append(formatted_entry) | ||
|
||
global STUDENTS | ||
global GROUPING_SIZE | ||
|
||
# EMAIL_COL = 0 | ||
# PREFERENCES_COL = 1 | ||
# SKILLS_COLS = [2, 3, 4, 5, 6] | ||
|
||
DATA = pd.read_csv(constants.WORKBOOK_CSV, header=None) | ||
|
||
EMAILS = DATA.iloc[:, EMAIL_COL] | ||
|
||
STUDENTS = list() | ||
for current_row, email in enumerate(EMAILS): | ||
skills = list() | ||
for skill_col in SKILLS_COLS: | ||
skills.append(DATA.iat[current_row, skill_col]) | ||
preferences_str = DATA.iat[current_row, PREFERENCES_COL] | ||
|
||
if isinstance(preferences_str, float) and math.isnan(preferences_str): | ||
preferences = [] | ||
else: | ||
preferences = preferences_str.replace(" ", "").split(",") | ||
|
||
STUDENTS.append(Student(email, skills, preferences)) | ||
|
||
# for student in STUDENTS: | ||
# print(str(student) + "\n") | ||
|
||
GROUPING_SIZE = math.floor(len(STUDENTS) / group_size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters