|
@@ -10,7 +10,28 @@ import random
|
|
# modules imports
|
|
# modules imports
|
|
sys.path.insert(0, '') # trick to enable import of main folder module
|
|
sys.path.insert(0, '') # trick to enable import of main folder module
|
|
|
|
|
|
-import config as cfg
|
|
|
|
|
|
+# config imports
|
|
|
|
+import links.config as cfg
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def decoded_data(data):
|
|
|
|
+ decoded_data = str(base64.b64decode(data), "utf-8")
|
|
|
|
+
|
|
|
|
+ return decoded_data
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def encode_data(data):
|
|
|
|
+ json_data = json.dumps(data)
|
|
|
|
+ link_data = base64.b64encode(str(json_data).encode('utf-8'))
|
|
|
|
+
|
|
|
|
+ return link_data
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def extract_data(line):
|
|
|
|
+
|
|
|
|
+ data = line.replace('\n', '').split(';')
|
|
|
|
+
|
|
|
|
+ return (data[0], data[-1])
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
@@ -20,6 +41,7 @@ def main():
|
|
parser.add_argument('--data', type=str, help='data links to use', required=True)
|
|
parser.add_argument('--data', type=str, help='data links to use', required=True)
|
|
parser.add_argument('--scenes', type=int, help="number of scenes", required=True)
|
|
parser.add_argument('--scenes', type=int, help="number of scenes", required=True)
|
|
parser.add_argument('--users', type=int, help="number of users of experiment", required=True)
|
|
parser.add_argument('--users', type=int, help="number of users of experiment", required=True)
|
|
|
|
+ parser.add_argument('--userId', type=int, help="tell if user identifier is used or not", required=False, default=0)
|
|
parser.add_argument('--output', type=str, help="output filename of user links", required=True)
|
|
parser.add_argument('--output', type=str, help="output filename of user links", required=True)
|
|
|
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
@@ -27,12 +49,15 @@ def main():
|
|
p_data = args.data
|
|
p_data = args.data
|
|
p_scenes = args.scenes
|
|
p_scenes = args.scenes
|
|
p_users = args.users
|
|
p_users = args.users
|
|
|
|
+ p_userId = bool(args.userId)
|
|
p_output = args.output
|
|
p_output = args.output
|
|
|
|
|
|
|
|
+ print(p_userId)
|
|
|
|
+
|
|
# generate link for each scene
|
|
# generate link for each scene
|
|
with open(p_data, 'r') as f:
|
|
with open(p_data, 'r') as f:
|
|
lines = f.readlines()
|
|
lines = f.readlines()
|
|
- lines = [l.replace('\n', '') for l in lines]
|
|
|
|
|
|
+ data_lines = [extract_data(l) for l in lines]
|
|
|
|
|
|
nb_elements = len(lines)
|
|
nb_elements = len(lines)
|
|
|
|
|
|
@@ -48,14 +73,33 @@ def main():
|
|
|
|
|
|
output_f = open(filename_path, 'w')
|
|
output_f = open(filename_path, 'w')
|
|
|
|
|
|
- for _ in range(p_users):
|
|
|
|
-
|
|
|
|
- user_links = random.choices(lines, k=p_scenes)
|
|
|
|
|
|
+ for i in range(p_users):
|
|
|
|
+
|
|
|
|
+ scene_links = random.sample(data_lines, k=p_scenes)
|
|
|
|
|
|
# generate output line
|
|
# generate output line
|
|
- output_line = ""
|
|
|
|
- for link in user_links:
|
|
|
|
- output_line += link + ';'
|
|
|
|
|
|
+ output_line = str(i) + ';'
|
|
|
|
+ for scene_name, link in scene_links:
|
|
|
|
+
|
|
|
|
+ if p_userId:
|
|
|
|
+ data = link.split('?q=')
|
|
|
|
+
|
|
|
|
+ hostname = data[0]
|
|
|
|
+ link_data = data[1]
|
|
|
|
+
|
|
|
|
+ # decode and add user id link if asked
|
|
|
|
+ decoded_data_link = decoded_data(link_data)
|
|
|
|
+ json_data = json.loads(decoded_data_link)
|
|
|
|
+ json_data['userId'] = str(i)
|
|
|
|
+ encoded_data_link = encode_data(json_data)
|
|
|
|
+ new_link = hostname + '?q=' + str(encoded_data_link, "utf-8")
|
|
|
|
+
|
|
|
|
+ # add new link
|
|
|
|
+ output_line += scene_name + ':::' + new_link + ';'
|
|
|
|
+ else:
|
|
|
|
+ output_line += scene_name + ':::' + link + ';'
|
|
|
|
+
|
|
|
|
+
|
|
output_line += '\n'
|
|
output_line += '\n'
|
|
|
|
|
|
output_f.write(output_line)
|
|
output_f.write(output_line)
|