DCSOlympus/scripts/payLoadConverter.py
WoodyXP a23659a815
Added Code to payloadNames.js and Updated payLoadConverter.py for the Code (#34)
* Added CLSID to payloadNames.js, Updated the payLoadConverter.py so the CLSID can be added, Added 1 custom Loadout in unitPayloads.lue

* Added emtpy Loadouts for all aircraft
2023-02-14 16:01:38 +01:00

62 lines
2.2 KiB
Python

import pandas as pd
import json
# Load data from an Excel file
df = pd.read_excel('data.xlsx')
# Group by 'Name', 'Fuel', 'Loadout Name', 'Role', and 'Code' and aggregate 'Items - Name' and 'Items - Quantity'
grouped = df.groupby(['Name', 'Fuel', 'Loadout Name', 'Role', 'Code'])['Items - Name', 'Items - Quantity'].agg(lambda x: list(x)).reset_index()
# Convert the grouped data into the desired format
result = {}
for index, row in grouped.iterrows():
name = row['Name']
if name not in result:
result[name] = {
"name": row['Name'],
"label": row['Name'],
"loadouts": [
{
"fuel": row['Fuel'],
"items": [
{
"name": item,
"quantity": quantity
} for item, quantity in zip(row['Items - Name'], row['Items - Quantity'])
],
"roles": [row['Role']],
"code": row['Code'],
"loadout_name": row['Loadout Name']
}
]
}
else:
found = False
for loadout in result[name]["loadouts"]:
if loadout["fuel"] == row['Fuel'] and loadout["code"] == row['Code'] and loadout["loadout_name"] == row['Loadout Name']:
loadout["items"].extend([
{
"name": item,
"quantity": quantity
} for item, quantity in zip(row['Items - Name'], row['Items - Quantity'])
])
loadout["roles"].append(row['Role'])
found = True
break
if not found:
result[name]["loadouts"].append({
"fuel": row['Fuel'],
"items": [
{
"name": item,
"quantity": quantity
} for item, quantity in zip(row['Items - Name'], row['Items - Quantity'])
],
"roles": [row['Role']],
"code": row['Code'],
"loadout_name": row['Loadout Name']
})
# Print the result with the correct indents
print(json.dumps(result, indent=2))