Commit 38b8a85a authored by Marco Schmiedel's avatar Marco Schmiedel

fix

parent 832a665b
{
"fileId": "01509001-bd4e-4462-93ad-dc5066fd729a",
"originalPath": "work/models/deal_deal.py",
"currentPath": "work/models/deal_deal.py",
"hash": "099f755dbb69b9e183dcf39898a9cb00f6eed50a9fede3188d0171f421476186",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744626243451,
"lastFileModificationTimestamp": 1744625938604.1194,
"flaggedForCopy": false
}
{
"fileId": "24784b38-54dc-4000-9d2a-f59082ebbc1c",
"originalPath": "work/models/base_base.py",
"currentPath": "work/models/base_base.py",
"hash": "ac06e8d1df3e4d73f4cc72b071faaf8536fdf8471b453e384512b98845b4e566",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744626237630,
"lastFileModificationTimestamp": 1744625911470.088,
"flaggedForCopy": false
}
{
"fileId": "2bcab2ab-e02d-4503-b29c-4b741cff2c87",
"originalPath": "work/notebooks/ImportBase.ipynb",
"currentPath": "work/notebooks/ImportBase.ipynb",
"hash": "a783a40298808a6c9db766ba799d8503e525e1a0389729dc54a96d0d512399c1",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744626641878,
"lastFileModificationTimestamp": 1744626637248.7,
"flaggedForCopy": false
}
{
"fileId": "2d1520cf-72fc-48b2-9249-380bc40499ed",
"originalPath": "work/notebooks/GetDataFromMaui.ipynb",
"currentPath": "work/notebooks/GetDataFromMaui.ipynb",
"hash": "e2d6ebb28291ed4181c547bd6dee318102be9f937145e1dfeb6c1ff0a001cb39",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744625554372,
"lastFileModificationTimestamp": 1744625453090.3838
}
{
"fileId": "38b9eebe-955e-4052-a0f6-29c69b1242b3",
"originalPath": "work/config/MysqlConfig.py",
"currentPath": "work/config/MysqlConfig.py",
"hash": "f9c624640584ecc2400d5053b7b366a6b2305ecdf836221aa95e3e169254af79",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [
{
"commentId": "56c5adba-20f4-4524-a894-41f81ab7ca55",
"text": "This data is currently stored statically and should be dynamically linked to the Docker container at the appropriate time.",
"timestamp": 1744622354948
}
],
"lastCheckedTimestamp": 1744624735475,
"lastFileModificationTimestamp": 1744624729595.99
}
{
"fileId": "5d19e01b-5fd7-4215-8da7-6b0a95956727",
"originalPath": "work/models/_system.py",
"currentPath": "work/models/_system.py",
"hash": "86d0b6279cb483585f66646c598db95bbda853070ef80a5b05218826dea61299",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744626235100,
"lastFileModificationTimestamp": 1744625929875.2092
}
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
"fileId": "5ec4e9ba-309d-438b-8e17-ce5802f3deb2", "fileId": "5ec4e9ba-309d-438b-8e17-ce5802f3deb2",
"originalPath": "work/workbench/Documentation.md", "originalPath": "work/workbench/Documentation.md",
"currentPath": "work/workbench/Documentation.md", "currentPath": "work/workbench/Documentation.md",
"hash": "7f2058d974b71f0a0da97fc41b918c41c33a4905c15cd54d189ec8d1311fa972", "hash": "f56f35397937e2b3c5e0f8507385b65d8afb0a3321c649466d9698212dc14a62",
"docContent": "<p><br></p>", "docContent": "<p><br></p>",
"checkedStatus": "done", "checkedStatus": "done",
"comments": [], "comments": [],
"lastCheckedTimestamp": 1744619683307, "lastCheckedTimestamp": 1744626251158,
"lastFileModificationTimestamp": 1744619461883.1462 "lastFileModificationTimestamp": 1744626180275.6394
} }
{
"fileId": "766dc461-001e-4901-8faf-263820ad96cd",
"originalPath": "work/manager/MysqlManager.py",
"currentPath": "work/manager/MysqlManager.py",
"hash": "c016d5cb9c9b391d19e41323196715c0e57b5838846232d2bdf761f53293e1b4",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744624751868,
"lastFileModificationTimestamp": 1744624748400.9556,
"flaggedForCopy": false
}
{
"fileId": "858c1430-9b46-4bb8-bb8d-4e5380be9c0d",
"originalPath": "work/models/provisiongroup_pgro.py",
"currentPath": "work/models/provisiongroup_pgro.py",
"hash": "3c4c4f905da78503daf856aa9f9ab1b0bac3e8c959ad23ec6f260f3964c8f98f",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744626248304,
"lastFileModificationTimestamp": 1744625950442.8225,
"flaggedForCopy": false
}
{
"fileId": "9384da7d-c01c-4108-8ada-f94de6e61346",
"originalPath": "work/models/basegroup_bgro.py",
"currentPath": "work/models/basegroup_bgro.py",
"hash": "46899d2f0bba4f6a2dcbe92272eccf5f4196411d4c15a0d65275d118bfafa758",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744626240017,
"lastFileModificationTimestamp": 1744625913887.2903,
"flaggedForCopy": false
}
{
"fileId": "e146d34c-9d63-4ea0-b8b8-5f8d503f34f6",
"originalPath": "work/models/option_opti.py",
"currentPath": "work/models/option_opti.py",
"hash": "b2da20cf0b8a0d239fc042773ecacca52777230bb7b2c418fe6d45d55fc3e37b",
"docContent": "<p><br></p>",
"checkedStatus": "done",
"comments": [],
"lastCheckedTimestamp": 1744626245976,
"lastFileModificationTimestamp": 1744625945396.1123,
"flaggedForCopy": false
}
<p><br></p>
\ No newline at end of file
# The MySQL host address.
MYSQL_HOST = "itmax-backoffice-prod-aurora-r3dbcluster-1e8hysitdwijk.cluster-crb5tahpiszg.eu-central-1.rds.amazonaws.com"
# The MySQL username for the connection.
MYSQL_USER = "labor-itmaxmaster"
# The MySQL password for the connection.
MYSQL_PASSWORD = "floz09sx3dTyx144gy"
# The MySQL database name.
MYSQL_DATABASE = "itmax_tarifs"
# The MySQL port number.
MYSQL_PORT = 3306
# If set to True, the MysqlManager will establish an SSH tunnel when connecting to MySQL.
USE_SSH_TUNNEL = True
# The SSH host address (the remote SSH server to tunnel through).
SSH_HOST = "jumphost.bugsmasher.online"
# The SSH port number (default is usually 22).
SSH_PORT = 22
# The SSH username for the tunnel.
SSH_USERNAME = "root"
# The SSH password for the tunnel.
SSH_PASSWORD = "7dHz2xO8ct1143T"
\ No newline at end of file
import sys; sys.path.append("..")
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import config.MysqlConfig as DatabaseConfig
from sshtunnel import SSHTunnelForwarder
# We create a new class called MysqlManager.
class MysqlManager:
# The following constructor initializes the MySQL connection.
def __init__(self):
# Instead of reading a configuration file, we import the Python configuration.
# We construct the configuration dictionary using values from the DatabaseConfig module.
self.config = {
"host": DatabaseConfig.MYSQL_HOST,
"user": DatabaseConfig.MYSQL_USER,
"password": DatabaseConfig.MYSQL_PASSWORD,
"database": DatabaseConfig.MYSQL_DATABASE,
"port": DatabaseConfig.MYSQL_PORT
}
# Check if an SSH tunnel should be used.
if getattr(DatabaseConfig, "USE_SSH_TUNNEL", False):
# Initialize the SSH tunnel using SSHTunnelForwarder.
self.tunnel = SSHTunnelForwarder(
(DatabaseConfig.SSH_HOST, DatabaseConfig.SSH_PORT),
ssh_username=DatabaseConfig.SSH_USERNAME,
ssh_password=DatabaseConfig.SSH_PASSWORD,
remote_bind_address=(self.config["host"], self.config["port"])
)
# Start the SSH tunnel.
self.tunnel.start()
# Set the host to localhost and port to the tunnel's local bind port.
host = "127.0.0.1"
port = self.tunnel.local_bind_port
else:
# No SSH tunnel is used.
self.tunnel = None
host = self.config["host"]
port = self.config["port"]
# Construct the MySQL engine using the connection details.
engine = create_engine(
f"mysql+pymysql://{self.config['user']}:{self.config['password']}@{host}:{port}/{self.config['database']}",
echo=False
)
# Start the database session.
self.session = sessionmaker(bind=engine)()
# "getSession" provides the database connection to other modules.
def getSession(self):
return self.session
# The following method closes the database connection and stops the SSH tunnel if active.
def close(self):
self.session.close()
if self.tunnel:
self.tunnel.stop()
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from models._system import Base
from models.basegroup_bgro import BasegroupBgro
class BaseBase(Base):
__tablename__ = 'base_base'
id_base = Column(Integer, primary_key=True, autoincrement=True)
basegroup_base = Column(Integer, ForeignKey('basegroup_bgro.id_bgro'))
provider_base = Column(String(255), nullable=False)
providercode_base = Column(String(255))
name_base = Column(String(255), nullable=False)
alias_base = Column(String(255))
network_base = Column(Integer, nullable=False)
type_base = Column(Integer, nullable=False)
created_base = Column(DateTime, nullable=False)
updated_base = Column(DateTime, nullable=False)
basegroup = relationship("BasegroupBgro", back_populates="bases")
deals = relationship("DealDeal", back_populates="base")
options = relationship("OptionOpti", back_populates="base")
from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy.orm import relationship
from models._system import Base
class BasegroupBgro(Base):
__tablename__ = 'basegroup_bgro'
id_bgro = Column(Integer, primary_key=True, autoincrement=True)
name_bgro = Column(String(255), nullable=False)
created_bgro = Column(DateTime, nullable=False)
updated_bgro = Column(DateTime, nullable=False)
bases = relationship("BaseBase", back_populates="basegroup")
from sqlalchemy import Column, Integer, String, Numeric, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from models._system import Base
from models.provisiongroup_pgro import ProvisiongroupPgro
class DealDeal(Base):
__tablename__ = 'deal_deal'
__table_args__ = {"mysql_engine": "InnoDB"}
id_deal = Column(Integer, primary_key=True, autoincrement=True)
provisiongroup_deal = Column(Integer, ForeignKey('provisiongroup_pgro.id_pgro'))
base_deal = Column(Integer, ForeignKey('base_base.id_base'), nullable=False)
providercode_deal = Column(String(255))
alias_deal = Column(String(255))
price_deal = Column(Numeric(8, 5), nullable=False)
starts_deal = Column(DateTime, nullable=False)
stops_deal = Column(DateTime)
provision1_deal = Column(Numeric(10, 5), nullable=False, default=0.00000)
provision2_deal = Column(Numeric(10, 5), nullable=False, default=0.00000)
provision3_deal = Column(Numeric(10, 5), nullable=False, default=0.00000)
provision4_deal = Column(Numeric(10, 5), nullable=False, default=0.00000)
created_deal = Column(DateTime, nullable=False)
updated_deal = Column(DateTime, nullable=False)
base = relationship("BaseBase", back_populates="deals")
provisiongroup = relationship("ProvisiongroupPgro", back_populates="deals")
from sqlalchemy import Column, Integer, String, Numeric, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from models._system import Base
from models.provisiongroup_pgro import ProvisiongroupPgro
class OptionOpti(Base):
__tablename__ = 'option_opti'
__table_args__ = {"mysql_engine": "InnoDB"}
id_opti = Column(Integer, primary_key=True, autoincrement=True)
provisiongroup_opti = Column(Integer, ForeignKey('provisiongroup_pgro.id_pgro'))
base_opti = Column(Integer, ForeignKey('base_base.id_base'), nullable=False)
providercode_opti = Column(String(255))
providercategory_opti = Column(String(255))
name_opti = Column(String(255), nullable=False)
alias_opti = Column(String(255))
price_opti = Column(Numeric(8, 5), nullable=False)
starts_opti = Column(DateTime, nullable=False)
stops_opti = Column(DateTime)
provision1_opti = Column(Numeric(10, 5), nullable=False, default=0.00000)
provision2_opti = Column(Numeric(10, 5), nullable=False, default=0.00000)
provision3_opti = Column(Numeric(10, 5), nullable=False, default=0.00000)
provision4_opti = Column(Numeric(10, 5), nullable=False, default=0.00000)
created_opti = Column(DateTime, nullable=False)
updated_opti = Column(DateTime, nullable=False)
base = relationship("BaseBase", back_populates="options")
provisiongroup = relationship("ProvisiongroupPgro", back_populates="options")
from sqlalchemy import Column, Integer, String, Numeric, DateTime
from sqlalchemy.orm import relationship
from models._system import Base
class ProvisiongroupPgro(Base):
__tablename__ = 'provisiongroup_pgro'
id_pgro = Column(Integer, primary_key=True, autoincrement=True)
name_pgro = Column(String(255), nullable=False)
percent_pgro = Column(Numeric(5, 2), nullable=False, default=0.00)
created_pgro = Column(DateTime, nullable=False)
updated_pgro = Column(DateTime)
deals = relationship("DealDeal", back_populates="provisiongroup")
options = relationship("OptionOpti", back_populates="provisiongroup")
This diff is collapsed.
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "193fb1fb-6ad1-447e-b641-73857be9d9dd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done\n"
]
}
],
"source": [
"#!/usr/bin/env python3\n",
"\n",
"# Importiert das Modul sys, damit auf Systemfunktionen zugegriffen werden kann.\n",
"import sys\n",
"\n",
"# Fügt das übergeordnete Verzeichnis zum Python-Pfad hinzu, damit lokale Module gefunden werden.\n",
"sys.path.append(\"..\")\n",
"\n",
"# Importiert das Modul os, um Betriebssystemfunktionen wie Pfadoperationen zu nutzen.\n",
"import os\n",
"\n",
"# Importiert das Modul csv, um CSV-Dateien einlesen und verarbeiten zu können.\n",
"import csv\n",
"\n",
"# Importiert das Modul datetime, um Datums- und Zeitfunktionen zu verwenden.\n",
"import datetime\n",
"\n",
"# Importiert die Klasse MysqlManager, um eine Verbindung zur MySQL-Datenbank herzustellen.\n",
"from manager.MysqlManager import MysqlManager\n",
"\n",
"# Importiert die Basisklasse Base, um SQLAlchemy-Modelle zu definieren.\n",
"from models._system import Base\n",
"\n",
"# Importiert die Klasse BasegroupBgro, um auf die Tabelle basegroup_bgro zuzugreifen.\n",
"from models.basegroup_bgro import BasegroupBgro\n",
"\n",
"# Importiert die Klasse BaseBase, um auf die Tabelle base_base zuzugreifen.\n",
"from models.base_base import BaseBase\n",
"\n",
"# Importiert die Klasse ProvisiongroupPgro, um auf die Tabelle provisiongroup_pgro zuzugreifen.\n",
"from models.provisiongroup_pgro import ProvisiongroupPgro\n",
"\n",
"# Importiert die Klasse DealDeal, um auf die Tabelle deal_deal zuzugreifen.\n",
"from models.deal_deal import DealDeal\n",
"\n",
"# Importiert die Klasse OptionOpti, um auf die Tabelle option_opti zuzugreifen.\n",
"from models.option_opti import OptionOpti\n",
"\n",
"# Definiert den Pfad zur CSV-Datei im Cache-Verzeichnis.\n",
"csv_file_path = os.path.join('..', 'cache', 'plans.csv')\n",
"\n",
"# Erzeugt eine Instanz des MysqlManagers, um die MySQL-Verbindung zu verwalten.\n",
"mysql_manager = MysqlManager()\n",
"\n",
"# Öffnet eine neue Session über den MysqlManager, um Datenbankoperationen durchzuführen.\n",
"session = mysql_manager.getSession()\n",
"\n",
"# Öffnet die CSV-Datei im Lese-Modus mit UTF-8-Kodierung und Semikolon als Trennzeichen.\n",
"with open(csv_file_path, newline='', encoding='utf-8') as csvfile:\n",
"\n",
" # Erstellt ein DictReader-Objekt, um Zeilen aus der CSV-Datei als Dictionary abzurufen.\n",
" reader = csv.DictReader(csvfile, delimiter=';')\n",
" \n",
" # Durchläuft jede Zeile, die aus der CSV-Datei gelesen wird.\n",
" for row in reader:\n",
"\n",
" # Speichert den in der CSV-Datei angegebenen Wert 'id' in der Variable csv_id und entfernt Leerzeichen.\n",
" csv_id = row.get('id', '').strip()\n",
"\n",
" # Speichert den in der CSV-Datei angegebenen Wert 'provider' in der Variable provider und entfernt Leerzeichen.\n",
" provider = row.get('provider', '').strip()\n",
"\n",
" # Speichert den in der CSV-Datei angegebenen Wert 'network' in der Variable network und entfernt Leerzeichen.\n",
" network = row.get('network', '').strip()\n",
"\n",
" # Speichert den in der CSV-Datei angegebenen Wert 'name' in der Variable name und entfernt Leerzeichen.\n",
" name = row.get('name', '').strip()\n",
"\n",
" # Speichert den in der CSV-Datei angegebenen Wert 'price' in der Variable price und entfernt Leerzeichen.\n",
" price = row.get('price', '').strip()\n",
" \n",
" # Kombiniert den String \"Freenet | \" mit dem Wert aus provider, um provider_base_val zu erhalten.\n",
" provider_base_val = \"Freenet | \" + provider\n",
" \n",
" # Führt eine Abfrage auf der Tabelle base_base durch, um einen vorhandenen Datensatz mit der gleichen Kombination zu finden.\n",
" existing_record = session.query(BaseBase).filter_by(\n",
" provider_base=provider_base_val,\n",
" providercode_base=csv_id\n",
" ).first()\n",
" \n",
" # Prüft, ob bereits ein Datensatz mit dieser Kombination existiert.\n",
" if existing_record:\n",
"\n",
" # Überspringt die Verarbeitung für diesen Datensatz, da er bereits existiert.\n",
" continue\n",
" \n",
" # Überprüft, ob der Netzwerk-String \"D1\" ist, und setzt network_val auf 1.\n",
" if network == \"D1\":\n",
" network_val = 1\n",
"\n",
" # Überprüft, ob der Netzwerk-String \"D2\" ist, und setzt network_val auf 2.\n",
" elif network == \"D2\":\n",
" network_val = 2\n",
"\n",
" # Überprüft, ob der Netzwerk-String \"O2\" ist, und setzt network_val auf 4.\n",
" elif network == \"O2\":\n",
" network_val = 4\n",
"\n",
" # Setzt network_val auf 0, falls keine der oben genannten Bedingungen zutrifft.\n",
" else:\n",
" network_val = 0\n",
"\n",
" # Setzt den Typ für alle neuen Datensätze standardmäßig auf 0.\n",
" type_val = 0\n",
"\n",
" # Holt das aktuelle Datum und die aktuelle Uhrzeit für die Felder created_base und updated_base.\n",
" now = datetime.datetime.now()\n",
"\n",
" # Erzeugt ein neues BaseBase-Objekt mit den aus der CSV-Datei ausgelesenen und verarbeiteten Werten.\n",
" new_record = BaseBase(\n",
" provider_base=provider_base_val,\n",
" providercode_base=csv_id,\n",
" basegroup_base=1,\n",
" name_base=name,\n",
" network_base=network_val,\n",
" type_base=type_val,\n",
" created_base=now,\n",
" updated_base=now\n",
" )\n",
"\n",
" # Hängt dieses neue Objekt an die aktuelle Session an, damit es später in die Datenbank geschrieben wird.\n",
" session.add(new_record)\n",
"\n",
"# Überträgt alle gesammelten Änderungen an die Datenbank.\n",
"session.commit()\n",
"\n",
"# Schließt die offene Session, sodass keine weiteren Datenbankzugriffe mehr stattfinden.\n",
"session.close()\n",
"\n",
"# Gibt zum Abschluss eine kurze Meldung aus.\n",
"print(\"Done\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6387255-71e0-40b4-8579-674320efc4db",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "001e79bd-8dff-4753-8754-6ec3101784dd",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
...@@ -38,6 +38,7 @@ In diesem Feld wird das verwendete Funknetz definiert. ...@@ -38,6 +38,7 @@ In diesem Feld wird das verwendete Funknetz definiert.
### type_base ### type_base
Dieses Feld legt den Tariftyp fest. Dieses Feld legt den Tariftyp fest.
**Mögliche Werte:** **Mögliche Werte:**
- **0**: Unbekannt
- **1**: Voice - **1**: Voice
- **2**: Daten - **2**: Daten
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment