Josif_tepe

Untitled

Aug 7th, 2025
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.50 KB | None | 0 0
  1. import csv
  2.  
  3.  
  4. popravki = {'Murska Sobota Rakican': 'Murska Sobota',
  5.     'Crnomelj Doblice': 'Črnomelj',
  6.     'Letalisce Edvarda Rusjana Mari': 'Maribor',
  7.     'Letalisce Jozeta Pucnika Ljubl': 'Brnik',
  8.     'Ljubljana Bezigrad': 'Ljubljana',
  9.     'Kocevje': 'Kočevje',
  10.     'Smartno Pri Slovenj Gradcu': 'Smartno pri Slovenj Gradcu',
  11.     'Kredarica': 'Kredarica',
  12.     'Veliki Dolenci': 'Veliki Dolenci',
  13.     'Novo Mesto': 'Novo mesto',
  14.     'Nova Vas Na Blokah': 'Bloke',
  15.     'Celje Medlog': 'Celje',
  16.     'Portoroz Letalisce': 'Portorož',
  17.     'Topol Pri Medvodah': 'Topol pri Medvodah',
  18.     'Ratece Planica': 'Rateče'
  19.     }
  20.  
  21.  
  22. import unittest
  23. import warnings
  24. import os
  25.  
  26. def kodirnik_postaj():
  27.     kodirnik = {}
  28.     folder_path = 'vreme-po-sloveniji'
  29.     for file in os.listdir(folder_path):
  30.         file_path = os.path.join(folder_path, file)
  31.         stanica = ''
  32.         grad = ''
  33.         with open(file_path, "r") as f:
  34.             csv_reader = csv.reader(f)
  35.             is_first = True
  36.             for row in csv_reader:
  37.                 if is_first:
  38.                     is_first = False
  39.                     continue
  40.                 grad = row[5]
  41.                 stanica = row[0]
  42.                 break
  43.         grad = grad.split(',')[0]
  44.         grad = grad.split(" ")
  45.         new_grad = ''
  46.         for zbor in grad:
  47.             c = zbor[0]
  48.             c = c.upper()
  49.             tmp = zbor.lower()
  50.             new_grad += c
  51.             new_grad += tmp[1:]
  52.             new_grad += " "
  53.         new_grad = new_grad[:-1]
  54.  
  55.         kodirnik[new_grad] = stanica
  56.     return kodirnik
  57.  
  58.  
  59.  
  60. def popravi(kodirnik):
  61.     for key, item in popravki.items():
  62.         tmp = kodirnik[key]
  63.         kodirnik.pop(key)
  64.         kodirnik[item] = tmp
  65.     return kodirnik
  66.  
  67. def preberi_meritve(ime_postaje, kodirnik):
  68.     folder_path = 'vreme-po-sloveniji'
  69.     file_path_name= kodirnik[ime_postaje] + ".csv"
  70.     file_path = os.path.join(folder_path, file_path_name)
  71.     result_kodirnik = {}
  72.     is_first_row = True
  73.     with open(file_path, "r") as f:
  74.         c = csv.reader(f)
  75.         for row in c:
  76.             if is_first_row:
  77.                 is_first_row = False
  78.                 continue
  79.             date = row[1].split("-")
  80.             try:
  81.                 temp = float(row[10])
  82.                 temp /= 10.0
  83.                 result_kodirnik[(int(date[0]), int(date[1]), int(date[2]))] = temp
  84.  
  85.             except ValueError:
  86.                 temp = None
  87.  
  88.     return result_kodirnik
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. def mrzli_silvester(podatki):
  98.     najladna_temp = 2000000.0
  99.     najladna_godina = -1
  100.     for godina in range(1900, 2023):
  101.         if (godina, 12, 31) in podatki:
  102.             temp = podatki[(godina, 12, 31)]
  103.  
  104.             if temp <= najladna_temp:
  105.                 najladna_temp = temp
  106.                 najladna_godina = godina
  107.  
  108.     return najladna_godina
  109.  
  110.  
  111.  
  112. class Test(unittest.TestCase):
  113.     def setUp(self):
  114.         warnings.simplefilter("ignore", ResourceWarning)
  115.  
  116.     def test_01_kodirnik_postaj(self):
  117.         self.assertEqual({'Bilje': 'SIE00115106',
  118.                           'Celje Medlog': 'SIE00115176',
  119.                           'Crnomelj Doblice': 'SIE00114856',
  120.                           'Kocevje': 'SIE00114956',
  121.                           'Kredarica': 'SIE00105938',
  122.                           'Lesce': 'SIE00114966',
  123.                           'Letalisce Edvarda Rusjana Mari': 'SIE00115156',
  124.                           'Letalisce Jozeta Pucnika Ljubl': 'SIE00115146',
  125.                           'Lisca': 'SIE00115186',
  126.                           'Ljubljana Bezigrad': 'SIM00014015',
  127.                           'Murska Sobota Rakican': 'SIE00115196',
  128.                           'Nova Vas Na Blokah': 'SIE00115066',
  129.                           'Novo Mesto': 'SIE00115126',
  130.                           'Portoroz Letalisce': 'SIE00115166',
  131.                           'Postojna': 'SIE00115076',
  132.                           'Ratece Planica': 'SIE00115206',
  133.                           'Smartno Pri Slovenj Gradcu': 'SIE00115136',
  134.                           'Topol Pri Medvodah': 'SIE00115006',
  135.                           'Veliki Dolenci': 'SIE00115096',
  136.                           'Vojsko': 'SIE00115016'}
  137. ,                         kodirnik_postaj())
  138.  
  139.     def test_02_popravki(self):
  140.         kodirnik = {'Bilje': 'SIE00115106',
  141.                     'Celje Medlog': 'SIE00115176',
  142.                     'Crnomelj Doblice': 'SIE00114856',
  143.                     'Kocevje': 'SIE00114956',
  144.                     'Kredarica': 'SIE00105938',
  145.                     'Lesce': 'SIE00114966',
  146.                     'Letalisce Edvarda Rusjana Mari': 'SIE00115156',
  147.                     'Letalisce Jozeta Pucnika Ljubl': 'SIE00115146',
  148.                     'Lisca': 'SIE00115186',
  149.                     'Ljubljana Bezigrad': 'SIM00014015',
  150.                     'Murska Sobota Rakican': 'SIE00115196',
  151.                     'Nova Vas Na Blokah': 'SIE00115066',
  152.                     'Novo Mesto': 'SIE00115126',
  153.                     'Portoroz Letalisce': 'SIE00115166',
  154.                     'Postojna': 'SIE00115076',
  155.                     'Ratece Planica': 'SIE00115206',
  156.                     'Smartno Pri Slovenj Gradcu': 'SIE00115136',
  157.                     'Topol Pri Medvodah': 'SIE00115006',
  158.                     'Veliki Dolenci': 'SIE00115096',
  159.                     'Vojsko': 'SIE00115016'}
  160.         popravi(kodirnik)
  161.         self.assertEqual({'Bilje': 'SIE00115106',
  162.                           'Bloke': 'SIE00115066',
  163.                           'Brnik': 'SIE00115146',
  164.                           'Celje': 'SIE00115176',
  165.                           'Kočevje': 'SIE00114956',
  166.                           'Kredarica': 'SIE00105938',
  167.                           'Lesce': 'SIE00114966',
  168.                           'Lisca': 'SIE00115186',
  169.                           'Ljubljana': 'SIM00014015',
  170.                           'Maribor': 'SIE00115156',
  171.                           'Murska Sobota': 'SIE00115196',
  172.                           'Novo mesto': 'SIE00115126',
  173.                           'Portorož': 'SIE00115166',
  174.                           'Postojna': 'SIE00115076',
  175.                           'Rateče': 'SIE00115206',
  176.                           'Smartno pri Slovenj Gradcu': 'SIE00115136',
  177.                           'Topol pri Medvodah': 'SIE00115006',
  178.                           'Veliki Dolenci': 'SIE00115096',
  179.                           'Vojsko': 'SIE00115016',
  180.                           'Črnomelj': 'SIE00114856'}, kodirnik)
  181.  
  182.     def test_03_preberi_meritve(self):
  183.         kodirnik = kodirnik_postaj()
  184.         popravi(kodirnik)
  185.         podatki = preberi_meritve("Kredarica", kodirnik)
  186.         self.assertAlmostEqual(14.4, podatki[(2023, 8, 13)])
  187.         self.assertAlmostEqual(11.1, podatki[(2023, 10, 1)])
  188.         self.assertNotIn((2023, 10, 4), podatki)
  189.  
  190.     def test_04_mrzli_silvester(self):
  191.         kodirnik = kodirnik_postaj()
  192.         popravi(kodirnik)
  193.  
  194.         podatki = preberi_meritve("Kredarica", kodirnik)
  195.         self.assertEqual(1968, mrzli_silvester(podatki))
  196.  
  197.         podatki = preberi_meritve("Črnomelj", kodirnik)
  198.         self.assertEqual(1996, mrzli_silvester(podatki))
  199.  
  200.         podatki = preberi_meritve("Ljubljana", kodirnik)
  201.         self.assertEqual(1906, mrzli_silvester(podatki))
  202.  
  203.         podatki = preberi_meritve("Bloke", kodirnik)
  204.         self.assertEqual(1996, mrzli_silvester(podatki))
  205.  
  206.         podatki = preberi_meritve("Bilje", kodirnik)
  207.         self.assertEqual(1996, mrzli_silvester(podatki))
  208.  
  209.  
  210. if __name__ == "__main__":
  211.     unittest.main()
  212.  
Advertisement
Add Comment
Please, Sign In to add comment