Loop through List(Integer)

User avatar
Marco Grawunder
Posts: 272
Joined: Tue Jul 29, 2014 10:29 am
Location: Oldenburg, Germany
Contact:

Re: Loop through List(Integer)

Post by Marco Grawunder » Tue Nov 22, 2016 11:43 am

We have a wide range of functions on list. They are now documented on:

https://wiki.odysseus.offis.uni-oldenbu ... +Functions

I guess you need something like:

search(Object x,List l, boolean nextIfNotFound)

where you will get the first element in the sorted list l that is higher or equals x (for nextIfNotFound=true) lower or equals x (for nextIfNotFound=false)?

stefan
Posts: 85
Joined: Tue Jul 12, 2016 1:03 pm

Re: Loop through List(Integer)

Post by stefan » Tue Nov 22, 2016 2:35 pm

Hi Marco,

thank you very much for your input! I am not able to test it today but I will have a look at this tomorrow and I will provide an example if I cannot figure it out by myself (based on the list functions).

greetings,
Stefan

stefan
Posts: 85
Joined: Tue Jul 12, 2016 1:03 pm

Re: Loop through List(Integer)

Post by stefan » Wed Nov 23, 2016 6:01 pm

Hi Marco,

I prepaired an example for the tuples in one path. The relevant changes are in the attributes: waitingTime, departureTime, arrivalTime.
Based on the previous tuple the closest time in "monday" is used to calculate the waiting time and fill the departure time. departureTime + travelTime+switchTime = arrival time. Its not that easy to calculate it directly because the time 7:05 am is represented as 705. Maybe I will change that to "minutes since midnight" to make the calculation easier.

Initial Input:

Code: Select all

uuid;pathCnt;pathPos;monday;tuesday;wednesday;thursday;friday;saturday;sunday;comment;relType;fareStage;price;travelTime;switchTime;waitingTime;change;desiredDepartureTime;desiredDepartureWeekday;departureTime;arrivalTime;start;end
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;7;[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[112, 939, 1139, 1340, 1539, 1640, 1939, 2102, 2314];[112, 939, 1139, 1340, 1539, 1640, 1939, 2102, 2314];;SWITCH_TO;;0;0;2;0;1;705;monday;0;0;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;6;[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[103, 930, 1130, 1331, 1530, 1631, 1930, 2305];[103, 930, 1130, 1331, 1530, 1631, 1930, 2305];;CONNECTED_TO;1;0;9;0;0;0;705;monday;0;0;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;5;[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[100, 927, 1127, 1328, 1527, 1628, 1927, 2049, 2302];[100, 927, 1127, 1328, 1527, 1628, 1927, 2049, 2302];;CONNECTED_TO;2;0;3;0;0;0;705;monday;0;0;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;4;[];[];[];[];[];[];[];;SWITCH_TO;;0;0;2;0;1;705;monday;0;0;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;3;[];[];[];[];[];[];[];;CONNECTED_TO;2;0;4;0;0;0;705;monday;0;0;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;2;[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[635, 705, 735, 805, 835, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1535, 1605, 1635, 1705, 1735, 1805, 1835, 1905, 1935];[805, 835, 905, 935, 1005, 1035, 1105, 1135, 1205, 1235, 1305, 1335, 1405, 1435, 1505, 1535, 1605, 1635, 1705, 1735, 1805, 1835, 1905, 1935];;SWITCH_TO;;0;0;0;0;1;705;monday;0;0;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;1;[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[630, 700, 730, 800, 830, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1530, 1600, 1630, 1700, 1730, 1800, 1830, 1900, 1930];[800, 830, 900, 930, 1000, 1030, 1100, 1130, 1200, 1230, 1300, 1330, 1400, 1430, 1500, 1530, 1600, 1630, 1700, 1730, 1800, 1830, 1900, 1930];;CONNECTED_TO;D;0;5;0;0;0;705;monday;0;0;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;0;[];[];[];[];[];[];[];;SWITCH_TO;;0;0;0;0;1;705;monday;0;0;1,48E+12;1,48E+12

Desired result:

Code: Select all

uuid;pathCnt;pathPos;monday;tuesday;wednesday;thursday;friday;saturday;sunday;comment;relType;fareStage;price;travelTime;switchTime;waitingTime;change;desiredDepartureTime;desiredDepartureWeekday;departureTime;arrivalTime;start;end
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;7;[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[609, 939, 1139, 1241, 1342, 1539, 1640, 1939, 2102, 2314];[112, 939, 1139, 1340, 1539, 1640, 1939, 2102, 2314];[112, 939, 1139, 1340, 1539, 1640, 1939, 2102, 2314];;SWITCH_TO;;0;0;2;0;1;705;monday;939;941;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;6;[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[600, 930, 1130, 1231, 1333, 1530, 1631, 1930, 2052, 2305];[103, 930, 1130, 1331, 1530, 1631, 1930, 2305];[103, 930, 1130, 1331, 1530, 1631, 1930, 2305];;CONNECTED_TO;1;0;9;0;0;0;705;monday;930;939;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;5;[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[557, 927, 1127, 1228, 1329, 1527, 1628, 1927, 2049, 2302];[100, 927, 1127, 1328, 1527, 1628, 1927, 2049, 2302];[100, 927, 1127, 1328, 1527, 1628, 1927, 2049, 2302];;CONNECTED_TO;2;0;3;0;121;0;705;monday;927;930;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;4;[];[];[];[];[];[];[];;SWITCH_TO;;0;0;2;0;1;705;monday;724;726;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;3;[];[];[];[];[];[];[];;CONNECTED_TO;2;0;4;0;0;0;705;monday;720;724;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;2;[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[520, 530, 555, 620, 635, 650, 705, 720, 735, 750, 805, 820, 835, 850, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1520, 1535, 1550, 1605, 1620, 1635, 1650, 1705, 1720, 1735, 1750, 1805, 1820, 1835, 1850, 1905, 1920, 1935, 1950];[635, 705, 735, 805, 835, 905, 920, 935, 950, 1005, 1020, 1035, 1050, 1105, 1120, 1135, 1150, 1205, 1220, 1235, 1250, 1305, 1320, 1335, 1350, 1405, 1420, 1435, 1450, 1505, 1535, 1605, 1635, 1705, 1735, 1805, 1835, 1905, 1935];[805, 835, 905, 935, 1005, 1035, 1105, 1135, 1205, 1235, 1305, 1335, 1405, 1435, 1505, 1535, 1605, 1635, 1705, 1735, 1805, 1835, 1905, 1935];;SWITCH_TO;;0;0;0;0;1;705;monday;720;720;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;1;[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[515, 550, 615, 630, 645, 700, 715, 730, 745, 800, 815, 830, 845, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1515, 1530, 1545, 1600, 1615, 1630, 1645, 1700, 1715, 1730, 1745, 1800, 1815, 1830, 1845, 1900, 1915, 1930, 1945];[630, 700, 730, 800, 830, 900, 915, 930, 945, 1000, 1015, 1030, 1045, 1100, 1115, 1130, 1145, 1200, 1215, 1230, 1245, 1300, 1315, 1330, 1345, 1400, 1415, 1430, 1445, 1500, 1530, 1600, 1630, 1700, 1730, 1800, 1830, 1900, 1930];[800, 830, 900, 930, 1000, 1030, 1100, 1130, 1200, 1230, 1300, 1330, 1400, 1430, 1500, 1530, 1600, 1630, 1700, 1730, 1800, 1830, 1900, 1930];;CONNECTED_TO;D;0;5;0;10;0;705;monday;715;720;1,48E+12;1,48E+12
d83632e5-7054-4bab-82cc-0550a4a6ee44;0;0;[];[];[];[];[];[];[];;SWITCH_TO;;0;0;0;0;1;705;monday;705;705;1,48E+12;1,48E+12

The search functionality looks good, unfortunately I dont really understand how to use it. I tried:

Code: Select all

test := MAP(
	{
		expressions =
		[
			'search(monday,700,true)'
		]
	}, joinedNodeRel
)
But that results in "null" values.

greetings,
Stefan

User avatar
Marco Grawunder
Posts: 272
Joined: Tue Jul 29, 2014 10:29 am
Location: Oldenburg, Germany
Contact:

Re: Loop through List(Integer)

Post by Marco Grawunder » Wed Nov 23, 2016 6:19 pm

Hi Stefan,

yes ... this is one "problem" of Odysseus. Numbers are always parsed as Longs and the input of the List are Integer. Java allows not to compare these two without changing the type.

A simple solution would be:

Code: Select all

out = MAP({EXPRESSIONS = ['search(monday,toInteger(700),true)']}, input)
But I think we need to find a better solution for the parser (something like 700I or 700L)

Greetings,

Marco

User avatar
Marco Grawunder
Posts: 272
Joined: Tue Jul 29, 2014 10:29 am
Location: Oldenburg, Germany
Contact:

Re: Loop through List(Integer)

Post by Marco Grawunder » Thu Nov 24, 2016 11:21 am

Here is a starting example:

Code: Select all

#PARSER PQL
#ADDQUERY

forum = CSVFILESOURCE({
            schema = [
              ['uuid', 'String'],
              ['pathCnt', 'Integer'],
              ['nodePos', 'Integer'],
              ['monday', 'List(Integer)'],
              ['tuesday', 'List(Integer)'],
              ['wednesday', 'List(Integer)'],
              ['thursday', 'List(Integer)'],
              ['friday', 'List(Integer)'],
              ['saturday', 'List(Integer)'],
              ['sunday', 'List(Integer)'],
              ['comment', 'String'],
              ['relType', 'String'],
              ['fareStage', 'String'],
              ['price', 'Double'],
              ['travelTime', 'Long'],
              ['switchTime', 'Long'],
              ['waitingTime', 'Long'],
              ['change', 'Long'],
              ['desiredDepartureTime', 'Integer'],
              ['desiredDepartureWeekday', 'Long'],
              ['departureTime','Long'],
              ['arrivalTime','Long']
            ],
            trim = true,
            delimiter = ';',
            source = 'forum',
            filename = '${PROJECTPATH}/forumData1.csv'                    
          }                
        )
        
        
        
/// Put all depaturetimes to one list
nested = MAP({
            expressions = [
					['toList(monday,tuesday,wednesday,thursday,friday,saturday,sunday)','departures']
            ],
            KEEPINPUT = true,
            REMOVEATTRIBUTES = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday']
          },
          forum
        )
        
//// calc next possible departure time
 
calcStep1 = MAP({
            expressions = [
					['search(departures[desiredDepartureWeekday],desiredDepartureTime,true)','departureTime']													
            ],
            KEEPINPUT = true,
            REMOVEATTRIBUTES = ['departureTime']
          },
          nested
        )
I think you will find a solution for your next steps yourself ;-)

By the way: I added keepAttributes and removeAttributes to the relational map operator to reduce the manual repeating of attributes.

stefan
Posts: 85
Joined: Tue Jul 12, 2016 1:03 pm

Re: Loop through List(Integer)

Post by stefan » Sun Nov 27, 2016 6:46 pm

Hi Marco,

Thank you very much! Most of the (smaller) tasks are not that difficult but its hard to find the correct syntax...
I am working on the calculation steps and get stuck into such a problem:

To pass values from tuple to tuple I am using the Statemap Operator and to calculate the map operator. Is there a way to replace the value of on specific attribute instead of creating a new one?

Example:

Code: Select all

#RUNQUERY
calcStep2 := STATEMAP({
		expressions = [
			['eIf(nodeCnt!=0, __last_1.calcArrivalTime,desiredDepartureTime)','calcStartTime']
		],
		KEEPINPUT = true
	},
	calcStep1
)
Instead of creating a new attribute I want to copy the value of "calcArrivalTime" of the last node into the attribute "calcStartTime" of the current node - unless what "calcStartTime" contains. At the moment the operation results in an error because the attribute "calcStartTime" already exists.

Furthermore I am not sure at the moment if this is working as expected:
If nodeCnt != 0 then I want to pick the last arrival time, and write this value in calcStartTime. The calcStartTime is used to search the next departureTime that should be stored in the calcDepartureTime attribute. Then the calcArrivalTime is calculated based on calcDepartureTime and other values. This could look like this:

Code: Select all

#RUNQUERY
calcStep2 := STATEMAP({
		expressions = [
			['eIf(nodeCnt!=0, __last_1.calcArrivalTime,desiredDepartureTime)','calcStartTime'],
			['eIf(nodeCnt!=0, search(departures[desiredDepartureWeekday],calcStartTime,true),desiredDepartureTime)','calcDepartureTime'],
			['eIf(nodeCnt!=0, calcDepartureTime + travelTime + waitingTime + switchTime,desiredDepartureTime)','calcArrivalTime']
		],
		KEEPINPUT = true
	},
	calcStep1
)
I am not sure if the value of the first calculation ("calcStartTime") is set before the second calculation starts ("calcDepartureTime") and so on. I cannot split these calculations to multiple MAP/STATEMAP Operators because the calculation of tuple n is directly based on the values of tuple n-1. Actually it should work like a foor loop that processes several calculations for each tuple one by one before it starts with the next tuple. Is this possible with Odysseus? If I can provide additional information, please let me know.

EDIT: Alternatively it should be possible to concatenate the calculations to get a big calculation for each attribute. I will try this but it could become complex. :)

Thanks,
Stefan

User avatar
Marco Grawunder
Posts: 272
Joined: Tue Jul 29, 2014 10:29 am
Location: Oldenburg, Germany
Contact:

Re: Loop through List(Integer)

Post by Marco Grawunder » Mon Nov 28, 2016 9:51 am

Hi Stefan,

when you use keepInput, every Attribute will be copied from the input to the output. You can use remoteAttributes to remove these attributes from the copied input. They are still available for processing.

At the moment, you cannot use calculation results from the same map operation. It is not guaranteed that the order of calcuation is the same order as you gave in the expression list (although for the current (State)Map implementation this is the case). For the

Maybe, we can extend the MAP operator to allow to use calced input as given in your example, where _new_ attributes are created.

A "hack" would be to use the two functions kvRead(Key,Value) and rvWrite(Key,Value).

Greetings,

Marco

User avatar
Marco Grawunder
Posts: 272
Joined: Tue Jul 29, 2014 10:29 am
Location: Oldenburg, Germany
Contact:

Re: Loop through List(Integer)

Post by Marco Grawunder » Mon Nov 28, 2016 3:23 pm

We discussed it and currently, there are no plans to extend this operator.

What you can do with #DEFINE subexpression replace the parts of the expression that is common or, maybe even better, use multiple map operators.

stefan
Posts: 85
Joined: Tue Jul 12, 2016 1:03 pm

Re: Loop through List(Integer)

Post by stefan » Mon Nov 28, 2016 5:38 pm

Hi Marco,

thank you for your help!

I played a bit with the kvRead/kvWrite, thanks for the hint!

To show, what I've done here the relevant code:

Code: Select all


#RUNQUERY
calcStep1 := MAP({
		expressions = [
			['eIf(nodeCnt==0, kvWrite(("start"+n_uuid+toString(n_pathCnt)+toString(nodeCnt)),desiredDepartureTime),0)','tmp_calcStartTime'],
			['eIf(nodeCnt==0, desiredDepartureTime,0)','calcStartTime'],
			['eIf(nodeCnt==0, desiredDepartureTime,0)','calcDepartureTime'],
			['eIf(nodeCnt==0, desiredDepartureTime,0)','calcArrivalTime']
		],
		KEEPINPUT = true///,
		///REMOVEATTRIBUTES = ['calcStartTime', 'calcDepartureTime','calcArrivalTime']
	},
	nestedNodeRel
)


#RUNQUERY
calcStep2 := STATEMAP({
		expressions = [
			['eIf(nodeCnt!=0, kvWrite(("start"+n_uuid+toString(n_pathCnt)+toString(nodeCnt)),toInteger(nodeCnt)),0)','tmp_calcStartTime'],
			['eIf(nodeCnt!=0, kvRead(("start"+n_uuid+toString(n_pathCnt)+toString(toInteger(nodeCnt-1)))),desiredDepartureTime)','calcStartTime'],
			['eIf(nodeCnt!=0, toInteger(234),desiredDepartureTime)','calcDepartureTime'],
			['eIf(nodeCnt!=0, toInteger(345),desiredDepartureTime)','calcArrivalTime']
		],
		KEEPINPUT = true,
		REMOVEATTRIBUTES = ['calcStartTime', 'calcDepartureTime','calcArrivalTime', 'tmp_calcStartTime']
	},
	calcStep1
)
I create a key that consists of uuid (or md5) + pathCnt + nodeCnt. This is needed because I have to identify the previous node. In each node I write the keyvalue of the current node (at the moment just some example data) and read the keyvalue of the previous node. That works as expected. Now I have to insert the actual calculation.
This is really a "hack" and will result in 4-5 keyvalue pairs for each processed node. I could not find information in the wiki about this function. I am wondering what happens if this is running for a while and a huge amount of data is processed. When will this data be destroyed? I am a bit scared that this is not a way I should go... :)

greetings,
Stefan

User avatar
Marco Grawunder
Posts: 272
Joined: Tue Jul 29, 2014 10:29 am
Location: Oldenburg, Germany
Contact:

Re: Loop through List(Integer)

Post by Marco Grawunder » Tue Nov 29, 2016 9:41 am

Yes, this way it will crash :-D and the function is pretty new.

The only way to avoid this is not to use different keys for every run, but I think that you do not need kv* in any way:

If you want to reuse a calcuation from a former map operation this is not necessary. In CalcStep1 you can just write the value into the attribute: tmp_calcStartTime

Code: Select all

         ['eIf(nodeCnt==0, desiredDepartureTime,0)','tmp_calcStartTime'],

And the kvRead in the Statemap (calcStep2) just reads a former value __last_1.tmp_calcStartTime

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest