-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabeled_map_mover.py
More file actions
69 lines (51 loc) · 2.05 KB
/
labeled_map_mover.py
File metadata and controls
69 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Run after map_generator.py
"""
import os
from distutils.dir_util import copy_tree
import shutil
import pandas as pd
from random import sample
import time
#sampling_multiplier = 5
sampling_multiplier = 1
source_folder = 'D:\\mids\\real_parsed_data'
magic_folder = 'D:\\mids\\data\\stage'
mapping = pd.read_csv('mapping.csv')
magic_folder_directories =[os.path.join(magic_folder, o).rsplit('\\')[-1] for o in os.listdir(magic_folder)
if os.path.isdir(os.path.join(magic_folder,o))]
source_folder_directories =[os.path.join(source_folder, o).rsplit('\\')[-1] for o in os.listdir(source_folder)
if os.path.isdir(os.path.join(source_folder,o))]
print(time.ctime())
# for hash in source_folder_directories:
# copy_tree(source_folder + '\\' + hash, magic_folder + '\\' + hash)
#print(source_folder + '\\' + hash)
print(time.ctime())
positive_hashes = mapping[mapping['Label'] == 'Positive']['sha'].to_list()
negative_hashes = sample(mapping[mapping['Label'] == 'Negative']['sha'].to_list(), len(positive_hashes * sampling_multiplier))
#Mover
for hash in positive_hashes:
try:
files = os.listdir(magic_folder + '\\' + hash)
#purge non.py files
for file in files:
file_ext = file[-3:]
if file_ext != '.py':
os.remove(magic_folder + '\\' + hash + '\\' + file)
#move to folder in question
os.rename(magic_folder + '\\' + hash, magic_folder + '\\positive\\' + hash)
except:
print(f'error for hash: {hash} - continuing to the next one.')
for hash in negative_hashes:
try:
files = os.listdir(magic_folder + '\\' + hash)
#purge non.py files
for file in files:
file_ext = file[-3:]
if file_ext != '.py':
os.remove(magic_folder + '\\' + hash + '\\' + file)
#move to folder in question
os.rename(magic_folder + '\\' + hash, magic_folder + '\\negative\\' + hash)
except:
print(f'error for hash: {hash} - continuing to the next one.')
print('complete.')