Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict'
  2. const variant = require('./variants')
  3. const tariffs = {
  4. B: 'Berlin'
  5. , P: 'Potsdam'
  6. , S: 'Brandenburg (Havel)'
  7. , C: 'Cottbus'
  8. , G: 'urban area'
  9. , V: 'Frankfurt (Oder)'
  10. , L: 'rural area'
  11. , R: 'rural area'
  12. , M: 'Szczecin'
  13. }
  14. const R = []
  15. R[3] = '25-35km'; R[4] = '35-45km'; R[5] = '45-55km'; R[6] = '55-65km';
  16. R[7] = '65-75km'; R[8] = '75-85km'; R[9] = '85-95km';
  17. // todo: G2
  18. // todo: RA
  19. const coverages = {
  20. B: ['short trip', 'AB', 'BC', 'ABC']
  21. , S: [null, 'AB', 'BC', 'ABC']
  22. , G: [null, 'urban area']
  23. , L: [null, '2 zones', '3 zones', '4 zones']
  24. , R: R
  25. , M: ['urban area']
  26. }
  27. coverages.P = coverages.B
  28. coverages.C = coverages.S
  29. coverages.V = coverages.S
  30. const parse = (t) => {
  31. const ticket = {
  32. name: t.name
  33. , price: (t.price || t.prc) / 100
  34. , tariff: null
  35. , coverage: null
  36. }
  37. if (!t.shpCtx) return ticket
  38. let code
  39. try {code = JSON.parse(t.shpCtx).TLS}
  40. catch (e) {return ticket}
  41. if (!code) return ticket
  42. variant(ticket, code.slice(2))
  43. const tariff = code[0]
  44. if (tariff in tariffs) ticket.tariff = tariffs[tariff]
  45. const coverage = parseInt(code[1])
  46. if (coverages[tariff] && (coverage in coverages[tariff])) {
  47. ticket.coverage = coverages[tariff][coverage] || null
  48. }
  49. if (coverage === 0 && tariff !== 'M') ticket.shortTrip = true
  50. return ticket
  51. }
  52. module.exports = parse