Skip to content

Commit

Permalink
Merge pull request #50 from dseichter/batch_progress
Browse files Browse the repository at this point in the history
Batch progress
  • Loading branch information
dseichter authored Jan 7, 2025
2 parents f66e9bf + 5cfbd23 commit db9c2d3
Show file tree
Hide file tree
Showing 10 changed files with 508 additions and 74 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,6 @@ cython_debug/
# ignore auto generated files by VATValidation
config.json
src/config.json
src/batchstatus.json

.vscode/
Binary file modified images/batch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/single.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
345 changes: 343 additions & 2 deletions src/VATValidation.fbp

Large diffs are not rendered by default.

37 changes: 30 additions & 7 deletions src/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
import logging_config # Setup the logging # noqa: F401
import logging


logger = logging.getLogger(__name__)

columns = ["key1", "key2", "ownvat", "foreignvat", "company", "street", "zip", "town"]


def validatebatch(inputfile, outputfile="", type="vies", lang="en"):
def validatebatch(inputfile, outputfile="", type="vies", lang="en", statusupdate=False):
"""
Validate the batch file and write the results to the output file.
"""
Expand All @@ -43,20 +44,20 @@ def validatebatch(inputfile, outputfile="", type="vies", lang="en"):

match ext:
case "csv":
resultcode = processcsv(inputfile, outputfile, type, lang)
resultcode = processcsv(inputfile, outputfile, type, lang, statusupdate)
return resultcode
case "xlsx":
resultcode = processxlsx(inputfile, outputfile, type, lang)
resultcode = processxlsx(inputfile, outputfile, type, lang, statusupdate)
return resultcode
case "json":
resultcode = processjson(inputfile, outputfile, type, lang)
resultcode = processjson(inputfile, outputfile, type, lang, statusupdate)
return resultcode
case _:
logger.error("Unsupported file format")
return 127


def processcsv(inputfile, outputfile, type, lang):
def processcsv(inputfile, outputfile, type, lang, statusupdate):
try:
# read csv with columns
data = pd.read_csv(
Expand All @@ -66,11 +67,15 @@ def processcsv(inputfile, outputfile, type, lang):
)
# create a list to store the results
results = []
# write statistics
write_status_update(statusupdate, len(data), 0)
# iterate over the rows
for index, row in data.iterrows():
# skip first line, because it contains the column names
if index == 0:
continue
# write statistics
write_status_update(statusupdate, len(data), index)
# validate the row
message = single.validatesingle(
key1=row["key1"],
Expand Down Expand Up @@ -113,14 +118,18 @@ def processcsv(inputfile, outputfile, type, lang):
return 99


def processxlsx(inputfile, outputfile, type, lang):
def processxlsx(inputfile, outputfile, type, lang, statusupdate):
try:
# read the input file
data = pd.read_excel(inputfile, usecols=columns)
# create a list to store the results
results = []
# write statistics
write_status_update(statusupdate, len(data), 0)
# iterate over the rows
for index, row in data.iterrows():
# write statistics
write_status_update(statusupdate, len(data), index)
# validate the row
message = single.validatesingle(
key1=row["key1"],
Expand Down Expand Up @@ -156,13 +165,17 @@ def processxlsx(inputfile, outputfile, type, lang):
return 99


def processjson(inputfile, outputfile, type, lang):
def processjson(inputfile, outputfile, type, lang, statusupdate):
try:
data = pd.read_json(inputfile)
# create a list to store the results
results = []
# write statistics
write_status_update(statusupdate, len(data), 0)
# iterate over the rows
for index, row in data.iterrows():
# write statistics
write_status_update(statusupdate, len(data), index)
# validate the row
message = single.validatesingle(
key1=row["key1"],
Expand Down Expand Up @@ -196,3 +209,13 @@ def processjson(inputfile, outputfile, type, lang):
except Exception as e:
logging.error(f"An unexpected error occurred: {e}")
return 99


def write_status_update(statusupdate, total, current):
if statusupdate:
with open('batchstatus.json', 'w') as f:
data = {
"total": total,
"current": current + 1
}
json.dump(data, f)
36 changes: 35 additions & 1 deletion src/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,41 @@ def __init__( self, parent ):
bSizer12.Add( self.m_staticline10, 0, wx.EXPAND |wx.ALL, 5 )


bSizer9.Add( bSizer12, 1, wx.EXPAND, 5 )
bSizer9.Add( bSizer12, 0, wx.EXPAND, 5 )

fgSizer51 = wx.FlexGridSizer( 0, 2, 0, 0 )
fgSizer51.SetFlexibleDirection( wx.BOTH )
fgSizer51.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

self.staticText_RecordsFound = wx.StaticText( self.panelBatch, wx.ID_ANY, _(u"Records found"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticText_RecordsFound.Wrap( -1 )

fgSizer51.Add( self.staticText_RecordsFound, 0, wx.ALL, 5 )

self.staticText_RecordsFound = wx.StaticText( self.panelBatch, wx.ID_ANY, _(u"0"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticText_RecordsFound.Wrap( -1 )

fgSizer51.Add( self.staticText_RecordsFound, 0, wx.ALL, 5 )

self.staticText_Progress = wx.StaticText( self.panelBatch, wx.ID_ANY, _(u"Progress"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticText_Progress.Wrap( -1 )

fgSizer51.Add( self.staticText_Progress, 0, wx.ALL, 5 )

self.progressProcessing = wx.Gauge( self.panelBatch, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL )
self.progressProcessing.SetValue( 0 )
fgSizer51.Add( self.progressProcessing, 0, wx.ALL, 5 )


fgSizer51.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.staticText_ProcessingXofY = wx.StaticText( self.panelBatch, wx.ID_ANY, _(u"0/0"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticText_ProcessingXofY.Wrap( -1 )

fgSizer51.Add( self.staticText_ProcessingXofY, 0, wx.ALL, 5 )


bSizer9.Add( fgSizer51, 1, wx.EXPAND, 5 )


self.panelBatch.SetSizer( bSizer9 )
Expand Down
2 changes: 1 addition & 1 deletion src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')

VERSION = "v2024-11-06"
VERSION = "v2025-01-07"
UPDATEURL = 'https://api.github.com/repos/dseichter/VATValidation/releases/latest'
RELEASES = 'https://github.com/dseichter/VATValidation/releases'
NAME = 'VATValidation'
Expand Down
3 changes: 2 additions & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pandas==2.2.3
numpy==2.2.1
openpyxl==3.1.5
pyinstaller==6.11.1
defusedxml==0.7.1
defusedxml==0.7.1
watchdog==6.0.0
Loading

0 comments on commit db9c2d3

Please sign in to comment.