Skip to content

Commit

Permalink
Added Autosave + display image directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinWach committed Sep 13, 2024
1 parent 3a05f44 commit c8b8544
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 2 deletions.
62 changes: 60 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import threading
from threading import Thread
from datetime import datetime

logging.basicConfig(level=logging.DEBUG)

Expand All @@ -20,6 +21,9 @@
IMAGE_FOLDER = 'static/images'
image_pairs_lock = threading.Lock()

# Add this global variable near the top of the file
current_directory = None

def get_image_paths():
image_paths = []
for root, dirs, files in os.walk(IMAGE_FOLDER):
Expand Down Expand Up @@ -128,8 +132,47 @@ def serve_image():
mimetype = 'image/jpeg'
return send_file(image_path, mimetype=mimetype)

# Add this global variable to keep track of comparisons since last autosave
comparisons_since_autosave = 0

def autosave_rankings():
global elo_ranking

# Get current date
current_date = datetime.now().strftime("%Y-%m-%d")

# Save rankings
rankings = elo_ranking.get_rankings()
rankings_filename = f'image_rankings_autosave_{current_date}.csv'
with open(rankings_filename, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['Image', 'ELO', 'Uncertainty', 'Upvotes', 'Downvotes'])
for image, rating in rankings:
writer.writerow([
image,
round(rating.mu, 2),
round(rating.sigma, 2),
elo_ranking.upvotes.get(image, 0),
elo_ranking.downvotes.get(image, 0)
])

# Save comparisons
comparisons = elo_ranking.comparison_history
comparisons_filename = f'comparisons_autosave_{current_date}.csv'
with open(comparisons_filename, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['Winner', 'Loser'])
for winner, loser in comparisons:
if winner is None:
writer.writerow(['None', loser])
else:
writer.writerow([winner, loser])

app.logger.info(f"Autosave completed. Files saved: {rankings_filename}, {comparisons_filename}")

@app.route('/update_elo', methods=['POST'])
def update_elo():
global comparisons_since_autosave
data = request.json
winner = data['winner']
loser = data['loser']
Expand All @@ -138,6 +181,13 @@ def update_elo():
excluded_images.add(loser)
# Recalculate image pairs
initialize_image_pairs()

# Increment the counter and check if it's time to autosave
comparisons_since_autosave += 1
if comparisons_since_autosave >= 10:
autosave_rankings()
comparisons_since_autosave = 0

return jsonify({'success': True})

@app.route('/remove_image', methods=['POST'])
Expand Down Expand Up @@ -188,12 +238,14 @@ def directory_selection():
thread.join()

if directory:
global IMAGE_FOLDER, elo_ranking, image_pairs, current_pair_index
global IMAGE_FOLDER, elo_ranking, image_pairs, current_pair_index, comparisons_since_autosave, current_directory
IMAGE_FOLDER = directory
current_directory = directory # Save the selected directory
elo_ranking = TrueSkillRanking() # Reset the ELO rankings
initialize_image_pairs()
current_pair_index = 0 # Reset the current pair index
return jsonify({'success': True})
comparisons_since_autosave = 0 # Reset the autosave counter
return jsonify({'success': True, 'directory': directory})
else:
return jsonify({'success': False, 'error': 'No directory selected'})
except Exception as e:
Expand Down Expand Up @@ -324,6 +376,12 @@ def clear_excluded_images():
initialize_image_pairs()
return jsonify({'success': True})

# Add a new route to get the current directory
@app.route('/get_current_directory')
def get_current_directory():
global current_directory
return jsonify({'directory': current_directory if current_directory else None})

if __name__ == '__main__':
initialize_image_pairs()
app.run(debug=False, threaded=True)
41 changes: 41 additions & 0 deletions comparisons_autosave.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Winner,Loser
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hc3rgfd2 23e.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/542qsd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/GGGF$RT.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FlA1dumWIAAT_HW.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfhgfrvc.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fe5Xzz2WYAAWHQx.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fcu6vYVWIAAXn2I.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd t4123 sd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FRJgy5yXwAIezOF.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asda_expression.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf542.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Ddas31.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/fdsa34fvcx.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/a a asd asd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/ge52tfadasdfs.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/32331dasd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd asd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fe5Xzz0XoBIgakz.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asggf.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/6zhgfds.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd4123s.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gf45tasd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hc3rgfd2 23e.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/sdsd34ra.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf657zhs.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FlA1dusXkAAC22V.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf51.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/532efa.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FOZ8o7hWUAkyQs8.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfd654ewfd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hbv531sd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fb7CBBLXkAEXVdT.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/dddsda34fasad.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/6zhgfds.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfs 6e2.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdfasf23123w.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asf561wd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gf45tasd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd 4we asd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/2rgsfasd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/fdsfsdsdfs.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgf562wd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/vvfrf56zss43.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf6j56.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/afafs e e.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Ddas31.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/532efa.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/vvfrf56zss43.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf657zhs.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/jhghg53sd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hg64wfa.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdrawdf e.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gfdg552.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgf562wd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd4123s.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FQqPpuPWUAoYA0U.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdasd3f sd sd .jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdd33fa.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gvefvd sd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf6j56.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FWIE_NEXEAEpv9g.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf31vd.webp
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/th.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/sdfsdf444.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf51.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FUcqvJFWQAE7-KM.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FRJgy5yXwAIezOF.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hbdr3d.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/fdsa34fvcx.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/ddasd dsa 34ga.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd t4123 sd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/fdsae d.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/aasdfasdf31324.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fb7CBBLXkAEXVdT.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FaPUgTlXkAMX88p.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf4d.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd4ewsfasd a asd .jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/sdsd34ra.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/5zgdsyv.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/4tfdasdf sa.jfif
41 changes: 41 additions & 0 deletions comparisons_autosave_2024-09-13.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Winner,Loser
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/32331dasd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FUcqvJFWQAE7-KM.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/32331dasd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf542.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gf45tasd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FlA1dumWIAAT_HW.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asddsad45512.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gfdg552.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FaPUgTlXkAMX88p.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FlA1dumWIAAT_HW.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/ggfg34.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfhgf.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/E-EyrmjVEAMxsYF.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FRJgy5yXwAIezOF.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/sdsdf642.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd asd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asf561wd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gfs4tef.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgdfgas.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gfdgfd3rfa.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/AFAFASDFDS.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FUcqvJFWQAE7-KM.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/4tfdasdf sa.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/6trfd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asda_expression.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfhgfrvc.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FaPUgTlXkAMX88p.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FNXUrnbXIAMtRs0.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FUC9TuZWYAQA5OK.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfhgf.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdfh566ws.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/aasdfasdf31324.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/ddasdg24gd.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf6j56.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/GGGF$RT.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/fdsfsdsdfs.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FY3wFq4XwAAQSyr.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/dasd4rfsa.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/dasd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf41w.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd4123s.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd4ewsfasd a asd .jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hg64wfa.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdd33fa.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FOZ8o7hWUAkyQs8.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FUcqvKFXoAEOSEP.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd t4123 sd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gvefvd sd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfs 6e2.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdd33fa.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/vvfrf56zss43.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FQqPpuPWUAoYA0U.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd4123s.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd 4we asd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdfasf23123w.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hbdr3d.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfd654ewfd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fe5Xzz0XoBIgakz.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/fdsfsdsdfs.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/a a asd asd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hbv531sd.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgfs 6e2.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdfaf421.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/AFAFASDFDS.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fcu6vYVWIAAXn2I.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/5zgdsyv.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/dsds344q.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asd t4123 sd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/ggfg34.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/FWIE_NEXEAEpv9g.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fe5Xzz2WYAAWHQx.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/Fb7CBBLXkAEXVdT.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/GGGF$RT.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/th.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asda_expression.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/hgf562wd.jfif
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/E-EyrmjVEAMxsYF.jpg,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/d3qwe.jpg
C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/gfs4tef.jfif,C:/Users/Quentin Wach/Desktop/MU/DATA Library/Images/emiru/asdf4d.jfif
Loading

0 comments on commit c8b8544

Please sign in to comment.