zampieri commited on
Commit
b684cd1
·
1 Parent(s): c4fc411

enable zip files

Browse files
Files changed (2) hide show
  1. app.py +13 -18
  2. tinder_plots.py +13 -2
app.py CHANGED
@@ -23,7 +23,7 @@ def fn(files):
23
  if len(dfs) == 1:
24
  df = dfs[0]
25
  else:
26
- df = pd.concatenate(dfs) # TODO: Test this
27
 
28
  figs = [
29
  tinder_usage_overview(df),
@@ -64,29 +64,24 @@ def create_with_blocks():
64
  gr.Markdown(
65
  """
66
  # Explore your Tinder data
67
- Upload your data.json file and get interactive plots, just like in the example.
68
- Upload several files to compare stats.
 
69
  """
70
  )
71
  with gr.Accordion(
72
- "How to get your tinder data file?",
73
  open=False,
74
  ):
75
  gr.Markdown(
76
  """
77
  To get your data, visit https://www.help.tinder.com/hc/en-us/articles/115005626726-How-do-I-request-a-copy-of-my-personal-data-
78
- You can either upload directly the archive, or if you want to avoid uploading sensitive information
79
- (even though it is not processed on our side: you can check the source code!) you can extract
80
- the data.json file and remove all the sensitive informations. See below on how to do that.
81
- """
82
- )
83
- with gr.Accordion(
84
- "No data is storred on our side. Don't trust us? Expand to see how to cleanup your data!",
85
- open=False,
86
- ):
87
- gr.Markdown(
88
- """
89
- Keep only numbers using this small python script, then upload public_data.json instead:
90
  ```python
91
  import json
92
  file = "./data.json"
@@ -95,7 +90,7 @@ def create_with_blocks():
95
  new_data = {}
96
  new_data["Usage"] = {k:v for k,v in data["Usage"].items() if k not in ["idfa", "advertising_id"]}
97
  with open("./public_data.json", "w") as f:
98
- json.dump(new_data, f)
99
  ```
100
  """
101
  )
@@ -104,7 +99,7 @@ def create_with_blocks():
104
  value="./public_data.json",
105
  file_count="multiple",
106
  elem_id="upload-element",
107
- label="Upload your tinder data.json file(s)",
108
  )
109
  ]
110
  btn = gr.Button("Explore data!")
 
23
  if len(dfs) == 1:
24
  df = dfs[0]
25
  else:
26
+ df = pd.concat(dfs, join="inner")
27
 
28
  figs = [
29
  tinder_usage_overview(df),
 
64
  gr.Markdown(
65
  """
66
  # Explore your Tinder data
67
+ Upload your myData.zip or data.json file and get interactive plots, just like with the provided example file.
68
+
69
+ Upload several files at once to compare different stats.
70
  """
71
  )
72
  with gr.Accordion(
73
+ "How to get your tinder data files?",
74
  open=False,
75
  ):
76
  gr.Markdown(
77
  """
78
  To get your data, visit https://www.help.tinder.com/hc/en-us/articles/115005626726-How-do-I-request-a-copy-of-my-personal-data-
79
+ You shoud then receive a `myData.zip`. You can either upload directly the archive, or
80
+ you can extract the data.json file and remove all the sensitive informationsyou can to avoid uploading personal informations
81
+ (Which we would not look at on our side: you can check the source code!). See below on how to do anonymise your data.json.
82
+
83
+
84
+ Keep only numbers using this small python script, then upload public_data.json instead of data.json or myData.zip:
 
 
 
 
 
 
85
  ```python
86
  import json
87
  file = "./data.json"
 
90
  new_data = {}
91
  new_data["Usage"] = {k:v for k,v in data["Usage"].items() if k not in ["idfa", "advertising_id"]}
92
  with open("./public_data.json", "w") as f:
93
+ json.dump(new_data, f)
94
  ```
95
  """
96
  )
 
99
  value="./public_data.json",
100
  file_count="multiple",
101
  elem_id="upload-element",
102
+ label="Upload your tinder file(s)! Click on the cross at the top-right corner to upload new file(s)!",
103
  )
104
  ]
105
  btn = gr.Button("Explore data!")
tinder_plots.py CHANGED
@@ -6,6 +6,8 @@ from tqdm.auto import tqdm
6
  import plotly.graph_objects as go
7
  import tempfile
8
  import copy
 
 
9
 
10
  TEMPLATE_PLOT = None # "ggplot2"
11
 
@@ -14,8 +16,17 @@ def get_usage_df(file):
14
  if isinstance(file, tempfile._TemporaryFileWrapper):
15
  file = file.name
16
 
17
- with open(file) as f:
18
- data = json.load(f)
 
 
 
 
 
 
 
 
 
19
  new_data = {}
20
  new_data["date"] = []
21
  new_data["value"] = []
 
6
  import plotly.graph_objects as go
7
  import tempfile
8
  import copy
9
+ import zipfile
10
+ import os
11
 
12
  TEMPLATE_PLOT = None # "ggplot2"
13
 
 
16
  if isinstance(file, tempfile._TemporaryFileWrapper):
17
  file = file.name
18
 
19
+ if file.endswith(".zip"):
20
+ with tempfile.TemporaryDirectory() as tmp_dir:
21
+ with zipfile.ZipFile(file, "r") as zip_ref:
22
+ zip_ref.extractall(tmp_dir)
23
+ file = os.path.join(tmp_dir, "data.json")
24
+ with open(file) as f:
25
+ data = json.load(f)
26
+ else:
27
+ with open(file) as f:
28
+ data = json.load(f)
29
+
30
  new_data = {}
31
  new_data["date"] = []
32
  new_data["value"] = []