neuralworm commited on
Commit
e8bbf2e
1 Parent(s): 75d4ca3

initial commit

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -9,9 +9,9 @@ from datetime import datetime, timedelta
9
  import json
10
  import inflect
11
 
12
- # --- Hilfsfunktionen ---
13
  def calculate_gematria_sum(text):
14
- """Berechnet die Gematria-Summe eines gegebenen Textes."""
15
  if text:
16
  text_gematria = calculate_gematria(strip_diacritics(text))
17
  return text_gematria
@@ -33,12 +33,12 @@ def number_to_ordinal_word(number):
33
  return ordinal_dict.get(number, "")
34
 
35
  def date_to_words(date_string):
36
- """Konvertiert ein Datum im Format YYYY-MM-DD in die englische Schreibweise."""
37
  inf_engine = inflect.engine()
38
  date_obj = datetime.strptime(date_string, "%Y-%m-%d")
39
 
40
  year = date_obj.year
41
- if 1900 <= year <= 1999:
42
  year_words = f"{inf_engine.number_to_words(year // 100, andword='') } hundred"
43
  if year % 100 != 0:
44
  year_words += f" {inf_engine.number_to_words(year % 100, andword='')}"
@@ -54,19 +54,19 @@ def date_to_words(date_string):
54
  return output_text
55
 
56
  def perform_gematria_calculation_for_date_range(start_date, end_date):
57
- """Führt die Gematria-Berechnung für einen Datumsbereich durch."""
58
- logger.info(f"Startdatum: {start_date}, Enddatum: {end_date}")
59
  results = {}
60
  delta = timedelta(days=1)
61
  current_date = start_date
62
 
63
  while current_date <= end_date:
64
- # Datum in String umwandeln
65
  date_string = current_date.strftime("%Y-%m-%d")
66
  date_words = date_to_words(date_string)
67
- logger.info(f"Datum: {current_date}, Tagesname: {date_words}")
68
  gematria_sum = calculate_gematria_sum(date_words)
69
- logger.info(f"Gematria-Summe: {gematria_sum}")
70
 
71
  if gematria_sum not in results:
72
  results[gematria_sum] = []
@@ -81,7 +81,7 @@ def perform_gematria_calculation_for_date_range(start_date, end_date):
81
  return results
82
 
83
  def generate_json_output(results, start_date, end_date):
84
- """Generiert die JSON-Ausgabe mit dem Datumsbereich und den Ergebnissen."""
85
  result = {
86
  "DateRange": {
87
  "StartDate": start_date.strftime("%Y-%m-%d"),
@@ -91,24 +91,24 @@ def generate_json_output(results, start_date, end_date):
91
  }
92
  return json.dumps(result, indent=4, ensure_ascii=False)
93
 
94
- # --- Hauptanwendung mit Gradio ---
95
  with gr.Blocks() as app:
96
  with gr.Row():
97
- start_date = Calendar(type="datetime", label="Startdatum")
98
- end_date = Calendar(type="datetime", label="Enddatum")
99
 
100
- calculate_btn = gr.Button("Gematria für Zeitraum berechnen")
101
- json_output = gr.Textbox(label="JSON-Ausgabe")
102
 
103
- # --- Event-Handler ---
104
  def perform_calculation(start_date, end_date):
105
- """Führt die Berechnung aus und generiert die JSON-Ausgabe."""
106
- logger.info(f"perform_calculation aufgerufen mit: start_date={start_date}, end_date={end_date}")
107
  results = perform_gematria_calculation_for_date_range(start_date, end_date)
108
  json_result = generate_json_output(results, start_date, end_date)
109
  return json_result
110
 
111
- # --- Event-Trigger ---
112
  calculate_btn.click(
113
  perform_calculation,
114
  inputs=[start_date, end_date],
 
9
  import json
10
  import inflect
11
 
12
+ # --- Helper Functions ---
13
  def calculate_gematria_sum(text):
14
+ """Calculates the gematria sum of a given text."""
15
  if text:
16
  text_gematria = calculate_gematria(strip_diacritics(text))
17
  return text_gematria
 
33
  return ordinal_dict.get(number, "")
34
 
35
  def date_to_words(date_string):
36
+ """Converts a date in YYYY-MM-DD format to English words."""
37
  inf_engine = inflect.engine()
38
  date_obj = datetime.strptime(date_string, "%Y-%m-%d")
39
 
40
  year = date_obj.year
41
+ if 1100 <= year <= 1999:
42
  year_words = f"{inf_engine.number_to_words(year // 100, andword='') } hundred"
43
  if year % 100 != 0:
44
  year_words += f" {inf_engine.number_to_words(year % 100, andword='')}"
 
54
  return output_text
55
 
56
  def perform_gematria_calculation_for_date_range(start_date, end_date):
57
+ """Performs gematria calculation for a date range and groups by sum."""
58
+ logger.info(f"Start Date: {start_date}, End Date: {end_date}")
59
  results = {}
60
  delta = timedelta(days=1)
61
  current_date = start_date
62
 
63
  while current_date <= end_date:
64
+ # Convert date to string
65
  date_string = current_date.strftime("%Y-%m-%d")
66
  date_words = date_to_words(date_string)
67
+ logger.info(f"Date: {current_date}, Day Name: {date_words}")
68
  gematria_sum = calculate_gematria_sum(date_words)
69
+ logger.info(f"Gematria Sum: {gematria_sum}")
70
 
71
  if gematria_sum not in results:
72
  results[gematria_sum] = []
 
81
  return results
82
 
83
  def generate_json_output(results, start_date, end_date):
84
+ """Generates the JSON output with the date range and results."""
85
  result = {
86
  "DateRange": {
87
  "StartDate": start_date.strftime("%Y-%m-%d"),
 
91
  }
92
  return json.dumps(result, indent=4, ensure_ascii=False)
93
 
94
+ # --- Main Gradio App ---
95
  with gr.Blocks() as app:
96
  with gr.Row():
97
+ start_date = Calendar(type="datetime", label="Start Date")
98
+ end_date = Calendar(type="datetime", label="End Date")
99
 
100
+ calculate_btn = gr.Button("Calculate Gematria for Date Range")
101
+ json_output = gr.Textbox(label="JSON Output")
102
 
103
+ # --- Event Handlers ---
104
  def perform_calculation(start_date, end_date):
105
+ """Performs the calculation and generates the JSON output."""
106
+ logger.info(f"perform_calculation called with: start_date={start_date}, end_date={end_date}")
107
  results = perform_gematria_calculation_for_date_range(start_date, end_date)
108
  json_result = generate_json_output(results, start_date, end_date)
109
  return json_result
110
 
111
+ # --- Event Triggers ---
112
  calculate_btn.click(
113
  perform_calculation,
114
  inputs=[start_date, end_date],