Josif_tepe

Untitled

Aug 6th, 2025
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.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(s, kodirnik):
  68.     pass
  69.  
  70. def mrzli_silvester(podatki):
  71.     pass
  72. class Test(unittest.TestCase):
  73.     def setUp(self):
  74.         warnings.simplefilter("ignore", ResourceWarning)
  75.  
  76.     def test_01_kodirnik_postaj(self):
  77.         self.assertEqual({'Bilje': 'SIE00115106',
  78.                           'Celje Medlog': 'SIE00115176',
  79.                           'Crnomelj Doblice': 'SIE00114856',
  80.                           'Kocevje': 'SIE00114956',
  81.                           'Kredarica': 'SIE00105938',
  82.                           'Lesce': 'SIE00114966',
  83.                           'Letalisce Edvarda Rusjana Mari': 'SIE00115156',
  84.                           'Letalisce Jozeta Pucnika Ljubl': 'SIE00115146',
  85.                           'Lisca': 'SIE00115186',
  86.                           'Ljubljana Bezigrad': 'SIM00014015',
  87.                           'Murska Sobota Rakican': 'SIE00115196',
  88.                           'Nova Vas Na Blokah': 'SIE00115066',
  89.                           'Novo Mesto': 'SIE00115126',
  90.                           'Portoroz Letalisce': 'SIE00115166',
  91.                           'Postojna': 'SIE00115076',
  92.                           'Ratece Planica': 'SIE00115206',
  93.                           'Smartno Pri Slovenj Gradcu': 'SIE00115136',
  94.                           'Topol Pri Medvodah': 'SIE00115006',
  95.                           'Veliki Dolenci': 'SIE00115096',
  96.                           'Vojsko': 'SIE00115016'}
  97. ,                         kodirnik_postaj())
  98.  
  99.     def test_02_popravki(self):
  100.         kodirnik = {'Bilje': 'SIE00115106',
  101.                     'Celje Medlog': 'SIE00115176',
  102.                     'Crnomelj Doblice': 'SIE00114856',
  103.                     'Kocevje': 'SIE00114956',
  104.                     'Kredarica': 'SIE00105938',
  105.                     'Lesce': 'SIE00114966',
  106.                     'Letalisce Edvarda Rusjana Mari': 'SIE00115156',
  107.                     'Letalisce Jozeta Pucnika Ljubl': 'SIE00115146',
  108.                     'Lisca': 'SIE00115186',
  109.                     'Ljubljana Bezigrad': 'SIM00014015',
  110.                     'Murska Sobota Rakican': 'SIE00115196',
  111.                     'Nova Vas Na Blokah': 'SIE00115066',
  112.                     'Novo Mesto': 'SIE00115126',
  113.                     'Portoroz Letalisce': 'SIE00115166',
  114.                     'Postojna': 'SIE00115076',
  115.                     'Ratece Planica': 'SIE00115206',
  116.                     'Smartno Pri Slovenj Gradcu': 'SIE00115136',
  117.                     'Topol Pri Medvodah': 'SIE00115006',
  118.                     'Veliki Dolenci': 'SIE00115096',
  119.                     'Vojsko': 'SIE00115016'}
  120.         popravi(kodirnik)
  121.         self.assertEqual({'Bilje': 'SIE00115106',
  122.                           'Bloke': 'SIE00115066',
  123.                           'Brnik': 'SIE00115146',
  124.                           'Celje': 'SIE00115176',
  125.                           'Kočevje': 'SIE00114956',
  126.                           'Kredarica': 'SIE00105938',
  127.                           'Lesce': 'SIE00114966',
  128.                           'Lisca': 'SIE00115186',
  129.                           'Ljubljana': 'SIM00014015',
  130.                           'Maribor': 'SIE00115156',
  131.                           'Murska Sobota': 'SIE00115196',
  132.                           'Novo mesto': 'SIE00115126',
  133.                           'Portorož': 'SIE00115166',
  134.                           'Postojna': 'SIE00115076',
  135.                           'Rateče': 'SIE00115206',
  136.                           'Smartno pri Slovenj Gradcu': 'SIE00115136',
  137.                           'Topol pri Medvodah': 'SIE00115006',
  138.                           'Veliki Dolenci': 'SIE00115096',
  139.                           'Vojsko': 'SIE00115016',
  140.                           'Črnomelj': 'SIE00114856'}, kodirnik)
  141.  
  142.     def test_03_preberi_meritve(self):
  143.         kodirnik = kodirnik_postaj()
  144.         popravi(kodirnik)
  145.         podatki = preberi_meritve("Kredarica", kodirnik)
  146.         self.assertAlmostEqual(14.4, podatki[(2023, 8, 13)])
  147.         self.assertAlmostEqual(11.1, podatki[(2023, 10, 1)])
  148.         self.assertNotIn((2023, 10, 4), podatki)
  149.  
  150.     def test_04_mrzli_silvester(self):
  151.         kodirnik = kodirnik_postaj()
  152.         popravi(kodirnik)
  153.  
  154.         podatki = preberi_meritve("Kredarica", kodirnik)
  155.         self.assertEqual(1968, mrzli_silvester(podatki))
  156.  
  157.         podatki = preberi_meritve("Črnomelj", kodirnik)
  158.         self.assertEqual(1996, mrzli_silvester(podatki))
  159.  
  160.         podatki = preberi_meritve("Ljubljana", kodirnik)
  161.         self.assertEqual(1906, mrzli_silvester(podatki))
  162.  
  163.         podatki = preberi_meritve("Bloke", kodirnik)
  164.         self.assertEqual(1996, mrzli_silvester(podatki))
  165.  
  166.         podatki = preberi_meritve("Bilje", kodirnik)
  167.         self.assertEqual(2005, mrzli_silvester(podatki))
  168.  
  169.  
  170. if __name__ == "__main__":
  171.     unittest.main()
  172.  
Advertisement
Add Comment
Please, Sign In to add comment