Skip to content

Instantly share code, notes, and snippets.

@zeyus
Created April 26, 2024 12:23
Show Gist options
  • Select an option

  • Save zeyus/d54f91344a4a0ed974937cf3c2dda43d to your computer and use it in GitHub Desktop.

Select an option

Save zeyus/d54f91344a4a0ed974937cf3c2dda43d to your computer and use it in GitHub Desktop.
Read in the collected data from the drawing experiment, display information about completed trials and save SVGs and PNGs
import csv
import sys
# pip install cairosvg
from cairosvg import svg2png
maxInt = sys.maxsize
while True:
# decrease the maxInt value by factor 10
# as long as the OverflowError occurs.
try:
csv.field_size_limit(maxInt)
break
except OverflowError:
maxInt = int(maxInt/10)
csv_file = "data/animalfeatures_2024-04-26.csv"
svg_dir = "data/svgs_2024-04-26"
png_dir = "data/pngs_2024-04-26"
# get number of rows that the "svg" column != "N/A" per "prolific_id"
drawings_per_participant = {}
with open(csv_file, mode='r') as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
if row["svg"] != "N/A" and row["svg"] != "":
if row["prolific_id"] in drawings_per_participant:
drawings_per_participant[row["prolific_id"]] += 1
else:
drawings_per_participant[row["prolific_id"]] = 1
base_filename = f"{row['prolific_id']}_{row['condition']}_{row['trial']}_{row['animal']}_{row['action']}"
# save contents of the svg column to a svg file
with open(f"{svg_dir}/{base_filename}.svg", "w") as svg_file:
svg_file.write(row["svg"])
# save contents of the svg column to a png file
svg2png(bytestring=row["svg"], write_to=f"{png_dir}/{base_filename}.png")
print("Number of participants with a drawing: ", len(drawings_per_participant))
# print how many have 16 completed drawings
count = 0
print("Number of drawings with content by participant:")
for key, value in drawings_per_participant.items():
print(key, ":", value)
if value == 16:
count += 1
# number of participants with complete drawings
print("Number of participants with 16 drawings: ", count)
@zeyus

zeyus commented Apr 26, 2024

Copy link
Copy Markdown
Author
Number of participants with a drawing:  89
Number of drawings with content by participant:
6112824dc733659aff681b33 : 1
5c33052cd4f77a0001a8ce56 : 1
61657b7fc08306b12b722115 : 16
5fa4faf94527261b54915c03 : 1
6004290f2fe8805383395886 : 16
5c3f8bdf342ae0000111a3e1 : 16
65ae8520028238caca8c4082 : 16
6165ee51589a30c811a48217 : 16
6145bf61521b5cddd6e4ebc3 : 3
65366ee5ac4d61b9d34f4d6b : 1
615c12b7b396c74155dc2185 : 16
613a98f9098c4cfe776b69d1 : 15
61320a26c3013321c8d54600 : 16
603e55e50ec4d3e1f1e976e1 : 1
6586e5f59b65330608147376 : 16
5daec9633990ed0014564662 : 16
60cfa6210e878af05a089060 : 16
5edad7d6f848291823c5f99c : 16
65032a60861e9a17bc1a7444 : 5
65de0a72fbc3bd908e63fbe5 : 16
609ea6976e377c8f9f77759a : 16
616c5387784afe4b70a34de7 : 16
5e5ba8c45cd2ad38c93ca999 : 16
5f09d989eff16b266fba44c0 : 2
56ebadebcdfa81000d9e2b67 : 16
60f1d99a67bc1538a6dadc94 : 2
66262b3e3e3f75131c582f35 : 16
65a53f52a8e15bf1de72f9fe : 16
5fb3fcb82df261033a5f6e0e : 16
612d16ff90c1ff5cff902e18 : 16
5fd7d4f8af92d60984a56d23 : 2
612b3134d6e373bd9f73afbf : 16
5ef17db9225ac500093b525a : 1
589630d22a697d0001cfca12 : 1
5c53ef4f26a39500019719b4 : 16
657bd47cdd8ce6a5aadd4c69 : 16
61574e3de0229e6bb92368c2 : 16
661fdfd33dfe00cbf53aca75 : 1
61516dcd44bbe2388c6d6f3a : 1
603cd9dda3d28fac931d45e5 : 16
611c5d79bfc8b929093b0506 : 16
60d1c40555cffd8ba5a3587e : 16
5e9f3b738bee310bed8379ad : 16
5d2d98a9a0d896001a5d6e4f : 1
65e48bfb93915b354fa3b66b : 16
5fda95fd9df7fa2b164bed61 : 16
65ddec4ce8c0b18582e05517 : 16
5f2efac9dc9a4e2be539b5d5 : 16
5fa670417aaa09285126c6b9 : 16
5ba8cac81299c60001e6701d : 16
6564a1d715b194ac6466d177 : 16
655779cc52010a3963da539d : 2
60d9dfd4dcc09cf57dc92cb1 : 16
616845bb92b48e8c6a18a84a : 16
5e8228e861db52053a287496 : 1
613ef4d99993c6d01d3eb04a : 16
64c8eb1ac199f433b0db2ab5 : 16
659570316debdec4ed9f663e : 16
611e20464a435b1b494f042d : 16
65b26a0d5ae1ede0b3be4248 : 16
648868e5d8e551227bf5da02 : 16
6162880049080f2ea6faa08e : 16
5bf9881e1eafa5000110c99a : 1
5c76c184719aaf00019ff241 : 1
61278ed955c9c0f27457ae1b : 2
5e8b11aaa9b690000bb6ae1f : 3
65b91010b2ea4aefcdc5900e : 1
6165bf9074ec655785050d87 : 16
651c425a4fd558465d845c57 : 2
602afb82e999ac1f112e7d5f : 15
656700a9c53734f641fea858 : 16
651c425a4fd558465d846c57 : 16
612f100e6abefeac4f3d4cd0 : 16
614775c6f329a9e5ab190e04 : 16
616dc333dc51cae13e5c21fc : 6
615d8873c11a1982c8838b54 : 1
58acbfacea3d11000170e99a : 4
6580e5dfdc7fc94823610ef5 : 16
660154442449690a354f6911 : 2
653e69acd1d1340f02fa4cbc : 1
6621503c947e5e6fe7830f1e : 16
6557ebf8541bd32382739c1a : 4
5c48be0496d59b000183e68d : 1
60cdae5d942a76a98eba611a : 4
6614daf007670261189c3e8a : 16
614b55e22ff3944a165736bb : 1
5fa94ee12438bf08ad45f75f : 16
6400e0dd862feacb579475a8 : 1
6509afd5de37875b4dbed467 : 16
Number of participants with 16 drawings:  54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment