Created
January 23, 2023 16:55
-
-
Save linusgke/cd74bbac9d5208b738ba4209d4855241 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from datetime import datetime | |
from pprint import pprint | |
data = [] | |
with open("data.csv", newline="", encoding="utf8") as file: | |
reader = csv.DictReader(file, delimiter=";") | |
for row in reader: | |
data.append(row) | |
data = sorted(data, key=lambda row: int(row["Vorgangsnummer"])) | |
totalMoney = 0 | |
personMoneyMap = {} | |
lastRow = None | |
for row in data: | |
date = datetime.strptime(row["Datum"], "%d.%m.%Y %H:%M:%S") | |
if lastRow: | |
if row["Loginname"] == lastRow["Loginname"] and row["Ware"] == lastRow["Ware"]: | |
lastDate = datetime.strptime(lastRow["Datum"], "%d.%m.%Y %H:%M:%S") | |
delta = date - lastDate | |
if delta.total_seconds() <= 30: | |
if row["Loginname"] in personMoneyMap: | |
data = personMoneyMap[row["Loginname"]] | |
else: | |
data = {"money": 0, "count": 0} | |
price = float(row["Preis"].strip("€").replace(",", ".")) | |
totalMoney += price | |
data["money"] += price | |
data["count"] += 1 | |
personMoneyMap[row["Loginname"]] = data | |
lastRow = row | |
with open("duplicates.csv", "w", newline="", encoding="utf-8-sig") as file: | |
writer = csv.writer(file, delimiter=";") | |
writer.writerow(["Benutzername", "Anzahl Doppelbuchungen", "Rückerstattungsbetrag"]) | |
for username, data in personMoneyMap.items(): | |
writer.writerow( | |
[username, data["count"], str(data["money"]).replace(".", ",") + " €"] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment