Skip to content

Commit

Permalink
Merge pull request #74 from unb-mds/testando-machine-learning-para-en…
Browse files Browse the repository at this point in the history
…contrar-valores

adicionando ids
  • Loading branch information
moonshinerd authored Jul 3, 2024
2 parents 6e6bd96 + ac81520 commit abae8d6
Show file tree
Hide file tree
Showing 4 changed files with 66,412 additions and 33,193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
site/
myenv/
backend/venv/
venv/

# Logs
logs
Expand Down
23 changes: 23 additions & 0 deletions backend/data_collection/add_ids_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
import os
# Caminho para o arquivo JSON
file_path = os.path.join(os.getcwd(), 'backend/data_collection/database/data.json')
print(file_path)
# Carregar o JSON existente
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)

# Adicionar IDs incrementais apenas para itens que não possuem um ID
current_max_id = max((item['id'] for item in data if 'id' in item), default=0)
next_id = current_max_id + 1

for item in data:
if 'id' not in item:
item['id'] = next_id
next_id += 1

# Salvar o JSON com IDs adicionados
with open(file_path, 'w', encoding='utf-8') as file:
json.dump(data, file, ensure_ascii=False, indent=4)

print(f"IDs adicionados com sucesso a {next_id - current_max_id - 1} itens.")
Loading

0 comments on commit abae8d6

Please sign in to comment.