How to create a Dynamic Regression Model (ARIMAX) in R? - dynamic

I created an ARIMAX model. Unfortunately, the forecasting that is created is not as it should be.
I want to predict the clickthrough rate "ctr" and use 6 explanatory variables.
enter image description here
#Step 4: Fit the forecasting model (ARIMAX) to the data
Fit <- auto.arima(Oct_Mar[, "ctr"], xreg = as.matrix(Oct_Mar[, 2:7]))
#Step 5: Predict values for Apr
Forecast_ctr <- Fit %>% forecast(xreg = as.matrix(Oct_Mar[, 2:7], h=30)
#Step 6: Forecast values
Forecast_ctr
#Step 7: Plot the forecast
autoplot(Forecast_ctr)+ xlab("Anzahl an Tagen")+ ylab("CTR")
Dataset:
structure(list(date = c("2019.10.01", "2019.10.02", "2019.10.03",
"2019.10.04", "2019.10.05", "2019.10.06", "2019.10.07", "2019.10.08",
"2019.10.09", "2019.10.10", "2019.10.11", "2019.10.12", "2019.10.13",
"2019.10.14", "2019.10.15", "2019.10.16", "2019.10.17", "2019.10.18",
"2019.10.19", "2019.10.20", "2019.10.21", "2019.10.22", "2019.10.23",
"2019.10.24", "2019.10.25", "2019.10.26", "2019.10.27", "2019.10.28",
"2019.10.29", "2019.10.30", "2019.10.31", "2019.11.01", "2019.11.02",
"2019.11.03", "2019.11.04", "2019.11.05", "2019.11.06", "2019.11.07",
"2019.11.08", "2019.11.09", "2019.11.10", "2019.11.11", "2019.11.12",
"2019.11.13", "2019.11.14", "2019.11.15", "2019.11.16", "2019.11.17",
"2019.11.18", "2019.11.19", "2019.11.20", "2019.11.21", "2019.11.22",
"2019.11.23", "2019.11.24", "2019.11.25", "2019.11.26", "2019.11.27",
"2019.11.28", "2019.11.29", "2019.11.30", "2019.12.01", "2019.12.02",
"2019.12.03", "2019.12.04", "2019.12.05", "2019.12.06", "2019.12.07",
"2019.12.08", "2019.12.09", "2019.12.10", "2019.12.11", "2019.12.12",
"2019.12.13", "2019.12.14", "2019.12.15", "2019.12.16", "2019.12.17",
"2019.12.18", "2019.12.19", "2019.12.20", "2019.12.21", "2019.12.22",
"2019.12.23", "2019.12.24", "2019.12.25", "2019.12.26", "2019.12.27",
"2019.12.28", "2019.12.29", "2019.12.30", "2019.12.31", "2020.01.01",
"2020.01.02", "2020.01.03", "2020.01.04", "2020.01.05", "2020.01.06",
"2020.01.07", "2020.01.08", "2020.01.09", "2020.01.10", "2020.01.11",
"2020.01.12", "2020.01.13", "2020.01.14", "2020.01.15", "2020.01.16",
"2020.01.17", "2020.01.18", "2020.01.19", "2020.01.20", "2020.01.21",
"2020.01.22", "2020.01.23", "2020.01.24", "2020.01.25", "2020.01.26",
"2020.01.27", "2020.01.28", "2020.01.29", "2020.01.30", "2020.01.31",
"2020.02.01", "2020.02.02", "2020.02.03", "2020.02.04", "2020.02.05",
"2020.02.06", "2020.02.07", "2020.02.08", "2020.02.09", "2020.02.10",
"2020.02.11", "2020.02.12", "2020.02.13", "2020.02.14", "2020.02.15",
"2020.02.16", "2020.02.17", "2020.02.18", "2020.02.19", "2020.02.20",
"2020.02.21", "2020.02.22", "2020.02.23", "2020.02.24", "2020.02.25",
"2020.02.26", "2020.02.27", "2020.02.28", "2020.02.29", "2020.03.01",
"2020.03.02", "2020.03.03", "2020.03.04", "2020.03.05", "2020.03.06",
"2020.03.07", "2020.03.08", "2020.03.09", "2020.03.10", "2020.03.11",
"2020.03.12", "2020.03.13", "2020.03.14", "2020.03.15", "2020.03.16",
"2020.03.17", "2020.03.18", "2020.03.19", "2020.03.20", "2020.03.21",
"2020.03.22", "2020.03.23", "2020.03.24", "2020.03.25", "2020.03.26",
"2020.03.27", "2020.03.28", "2020.03.29", "2020.03.30", "2020.03.31"
), price_view = c(35.79, 180.16, 437.57, 10.3, 74.26, 79.8, 89.84,
121.24, 461.95, 142.06, 241.71, 52, 43.24, 41.16, 167.05, 764.06,
91.64, 189.82, 38.59, 152.64, 86.23, 321.33, 411.83, 256.88,
352.39, 76.32, 360.11, 123.53, 43.41, 149.38, 14.16, 489.07,
1661.74, 1253.07, 25.71, 154.42, 990.89, 1645.93, 144.12, 84.43,
240.25, 148.18, 41.13, 262.56, 168.78, 860.85, 239.31, 372.98,
165.64, 134.32, 20.7, 43.73, 765.76, 51.48, 599.49, 893.79, 155.29,
334.37, 46.82, 1814.72, 196.27, 1302.48, 40.16, 1161.68, 381.48,
184.48, 48.91, 221.11, 434.73, 149.27, 77.22, 882.49, 106.05,
669.23, 282.86, 179.67, 12.97, 460.24, 38.59, 278.26, 243.76,
1904.79, 84.93, 32.18, 25.71, 496.54, 29.6, 1466.83, 164.33,
234.76, 19.95, 308.37, 1130.02, 7.47, 79.8, 65.9, 746.45, 1347.78,
1270.82, 69.42, 231.41, 195.6, 715.33, 208.47, 720.46, 414.68,
24.45, 217.82, 434.45, 483.92, 1500.42, 318.15, 339.29, 267.45,
133.85, 9.03, 11.81, 280.57, 916.74, 58.51, 339.78, 33.98, 263.58,
19.31, 239.88, 489.07, 84.92, 344.9, 95.24, 99.1, 142.58, 480.58,
104.74, 14.83, 252, 1039.41, 28.3, 328.97, 341.55, 278.26, 43.73,
91.35, 102.32, 131.25, 155.15, 77.74, 14.67, 132.63, 1185.36,
291.13, 1106.59, 849.42, 117.63, 171.32, 167.31, 252.23, 248.14,
111.15, 257.15, 27.62, 169.86, 101.89, 282.89, 298.57, 86.49,
196.32, 1415.45, 898.35, 334.6, 17.99, 13.62, 566.27, 60.41,
36.34, 62.04, 308.81, 32.95, 127.44, 836.57, 221.34, 360.34,
159.31, 20.57), view = c(1206151L, 1152770L, 1087372L, 1344804L,
1270060L, 1262993L, 1159265L, 1323522L, 1301376L, 1240347L, 1445162L,
1432321L, 1583572L, 1376274L, 1462409L, 1443323L, 1337174L, 1413405L,
1382403L, 1443838L, 1342668L, 1353053L, 1318395L, 1252747L, 1369922L,
1288939L, 1330209L, 1220710L, 1187883L, 1169955L, 1207854L, 1402754L,
1513400L, 1524803L, 1743304L, 1670637L, 1644359L, 1748812L, 1789808L,
1783142L, 1845552L, 1907417L, 1892753L, 1920411L, 2864410L, 5691766L,
5986292L, 5759703L, 1905351L, 1627672L, 1598554L, 1573101L, 1471242L,
1474138L, 1500022L, 1496128L, 1557252L, 1547199L, 1560191L, 1727852L,
1644405L, 1706901L, 1629904L, 1547658L, 1468085L, 1540157L, 1652208L,
1725106L, 1724452L, 1627222L, 1651328L, 1605421L, 1650612L, 1634861L,
1760750L, 2167056L, 2875847L, 2780816L, 2665285L, 2528244L, 2387520L,
2340327L, 2471739L, 2372930L, 2326654L, 2322753L, 2240514L, 2058141L,
2089081L, 2474226L, 2294820L, 1603749L, 1427733L, 1700904L, 1765457L,
1754424L, 1738774L, 1696188L, 1701769L, 1585870L, 1556542L, 1557542L,
1618230L, 1645866L, 1627433L, 1612956L, 1555416L, 1773179L, 1826768L,
2021676L, 2104199L, 1801073L, 1733142L, 1593991L, 1645225L, 1557626L,
1637470L, 1721003L, 1545472L, 1594688L, 1565742L, 1651606L, 1999670L,
2217825L, 1985751L, 1680034L, 1608904L, 1620473L, 1628906L, 1726835L,
1589058L, 1714745L, 1751044L, 1896265L, 2429526L, 2268487L, 1935249L,
1916034L, 2239698L, 1916650L, 1981570L, 1948648L, 1987134L, 1749514L,
1822349L, 1830307L, 1748590L, 1734610L, 1798308L, 162557L, 1000204L,
1257475L, 1770064L, 2416707L, 2477258L, 2487470L, 2457500L, 2210539L,
2377633L, 2026050L, 2301337L, 2218894L, 2012789L, 1700619L, 1481115L,
1562027L, 1560348L, 1338829L, 1244973L, 1142989L, 1260747L, 1316975L,
1387394L, 1319559L, 1440470L, 1451015L, 1439649L, 1390411L, 1336076L,
1369834L, 1255626L, 1244163L, 1283731L), price_cart = c(29.51,
1415.48, 99.86, 358.57, 617.51, 1052.79, 1747.79, 190.56, 128.28,
252.38, 250.91, 720.48, 33.42, 643, 191.77, 460.11, 408.5, 789.9,
577.94, 49.36, 380.7, 19.56, 994.86, 756.71, 223.66, 437.33,
1684.28, 366.16, 968.34, 1683.07, 550.77, 503.09, 29.09, 179.67,
210.62, 22.66, 131.66, 68.96, 360.06, 494.22, 1023.62, 1569.92,
28.29, 694.97, 127.05, 37.85, 282.89, 178.9, 913.28, 1022.42,
424.7, 573.7, 1029.34, 30.12, 20.82, 17.99, 107.53, 41.19, 85.82,
1002.55, 140.98, 167.03, 231.67, 25.71, 205.64, 30.81, 51.22,
65.9, 7.08, 308.63, 227.79, 16.22, 7.89, 62.52, 48.88, 586.63,
602.07, 1312.26, 128.32, 179.9, 849.42, 100.9, 1284.2, 12.84,
128.42, 59.18, 176.99, 38.02, 48.88, 694.54, 262.3, 1402.84,
1453.18, 3.84, 453.01, 76.93, 7.04, 865.93, 865.4, 40.75, 1423.07,
1534.66, 679.27, 11.25, 102.63, 436.3, 853.93, 694.97, 850.47,
477.49, 1234.97, 10.27, 23.94, 643.23, 89.84, 290.34, 320.99,
6.44, 140.28, 188.89, 56.88, 1326.31, 194.34, 140.28, 771.96,
140.03, 20.21, 1464.39, 59.18, 57.92, 1156.81, 50.43, 300.12,
38.1, 832.71, 57.91, 174.5, 100.36, 248.14, 109.34, 100.7, 242.7,
266.67, 592.01, 242.18, 22.66, 566.04, 38.61, 812.06, 123.92,
168.6, 172.03, 49.91, 16.73, 108.04, 347.47, 97.79, 111.15, 514.79,
126.1, 178.87, 870.03, 529.31, 43.5, 2110.48, 771.94, 15.32,
105.25, 7.14, 312.67, 61.75, 165.51, 48.37, 643.49, 303.48, 35.78,
154.42, 209.71, 76.69, 25.46, 1415.45, 123.53, 602.31), cart = c(16658L,
17268L, 19323L, 43826L, 35493L, 32145L, 18052L, 18442L, 18432L,
18997L, 21450L, 20691L, 24833L, 44821L, 49513L, 45272L, 40368L,
40127L, 39455L, 40533L, 36675L, 36945L, 36407L, 35721L, 36800L,
34776L, 34256L, 17838L, 17455L, 16996L, 16798L, 18911L, 19350L,
20211L, 21960L, 19231L, 19670L, 19446L, 77319L, 70093L, 71585L,
75135L, 69669L, 71613L, 170183L, 481862L, 405584L, 426261L, 83117L,
72450L, 72311L, 75530L, 70171L, 64801L, 68099L, 71405L, 71622L,
71324L, 71504L, 92345L, 81760L, 84473L, 80869L, 70192L, 66718L,
71048L, 83618L, 84231L, 80773L, 80675L, 81420L, 78947L, 80162L,
82360L, 86689L, 109721L, 183764L, 155406L, 146906L, 137487L,
127900L, 124577L, 127381L, 126700L, 124797L, 127554L, 123966L,
120940L, 127769L, 148663L, 148608L, 119062L, 57614L, 71342L,
95608L, 80629L, 78782L, 79099L, 77396L, 74671L, 72772L, 74827L,
72221L, 73406L, 72999L, 71182L, 70235L, 79414L, 104791L, 103481L,
102597L, 94354L, 90666L, 83642L, 83223L, 73075L, 73582L, 73849L,
70067L, 71600L, 72179L, 130757L, 208231L, 169156L, 137970L, 116560L,
104701L, 102836L, 101145L, 101605L, 90864L, 92635L, 95114L, 100283L,
158447L, 131720L, 118661L, 126405L, 132399L, 98277L, 96270L,
95284L, 96886L, 89046L, 91384L, 89585L, 83771L, 83241L, 84151L,
6104L, 40574L, 48944L, 81869L, 146953L, 135144L, 132819L, 134255L,
131648L, 141696L, 122204L, 122752L, 120927L, 112159L, 102239L,
95998L, 97600L, 99032L, 79662L, 76622L, 69585L, 73822L, 74488L,
75621L, 69098L, 73761L, 76429L, 75664L, 77671L, 77090L, 77835L,
68888L, 69091L, 73986L), price_purchase = c(130.76, 419.6, 251.74,
252.88, 64.02, 272.59, 172.72, 88.81, 28.73, 1003.86, 346.47,
130.48, 29.86, 280.11, 358.57, 385.83, 287.61, 22.95, 58.08,
854.08, 28.28, 62.91, 994.86, 51.22, 9.01, 77.21, 244.15, 366.16,
366.8, 213.25, 35.52, 566.3, 35.78, 1106.82, 64.35, 722.18, 131.66,
166.1, 823.9, 138.23, 334.6, 328.19, 243.51, 488.8, 159.57, 106.8,
54.03, 27, 308.63, 1022.42, 463.31, 144.66, 44.53, 25.48, 126.18,
365.52, 133.92, 97.27, 12.84, 1002.55, 107.41, 132.31, 131.2,
789.57, 230.2, 12.36, 229.86, 1386.91, 154.19, 18.19, 76.96,
882.49, 191.55, 46.08, 24.17, 102.65, 326.62, 924.06, 923.73,
88.29, 41.16, 128.42, 326.88, 137.96, 30.68, 108.88, 181.19,
241.34, 128.32, 137.46, 1279.81, 643.23, 1275.16, 717.245, 159.33,
745.37, 288.27, 177.26, 168.58, 66.85, 331.51, 437.31, 643.23,
9.3, 0.85, 436.3, 105.51, 7.7, 79.44, 1321.37, 160.89, 107.21,
172.25, 514.79, 141.06, 900.64, 153.22, 924.4, 176.34, 94.98,
162.6, 1326.25, 39.9, 38.15, 2162.22, 180.95, 153.41, 720.48,
720.48, 15.42, 140.28, 514.02, 720.47, 174.7, 197.69, 411.08,
741.07, 230.12, 501.89, 109.34, 643.26, 23.17, 242.48, 1317.36,
69.76, 178.11, 153.55, 32.18, 812.06, 302.2, 153.34, 172.03,
128.68, 939.54, 108.04, 165.89, 56.63, 43.76, 171.17, 98.59,
21.95, 280.28, 181.47, 730.01, 159.31, 60.75, 31.15, 1412.39,
7.14, 942.84, 321.06, 165.51, 284.95, 169.42, 303.48, 224.3,
416.43, 385.85, 492.08, 334.6, 1415.45, 123.53, 308.55), purchase = c(19307,
19469, 19255, 27041, 23494, 22171, 21378, 23072, 22748, 21993,
26224, 25373, 29561, 28405, 26372, 31394, 28318, 25850, 24657,
25098, 25167, 25385, 24731, 23999, 23929, 22653, 23403, 21112,
20374, 20817, 20099, 22458, 21864, 22145, 26889, 24875, 25319,
24863, 25714, 22768, 22878, 24931, 22725, 22548, 22124, 45185.5,
68247, 185195, 28537, 24967, 24947, 25266, 24187, 22243, 23163,
24827, 24226, 24443, 24305, 32107, 28178, 28345, 28548, 24358,
24473, 25469, 27505, 27012, 25766, 26802, 27059, 25906, 26044,
26712, 26559, 35077, 63796, 51899, 49578, 48212, 46405, 44255,
44719, 46602, 44917, 44949, 44154, 43081, 45287, 49597, 50729,
38233, 3574, 13975.5, 24377, 28938, 28427, 28875, 27722, 27510,
26492, 27481, 26059, 25869, 27525, 26322, 27121, 29614, 35086,
32884, 32548, 32619, 31698, 30089, 30398, 27579, 26662, 26880,
27052, 26841, 27403, 27612, 33750, 32536, 32308, 28645, 27652,
28276, 28533, 28426, 25379, 26027, 46480, 60013, 102117, 83216,
76048, 72365, 87586, 63260, 36377, 31438, 31258, 29324, 28946,
29017, 27884, 28063, 27809, 27499, 27490, 26316, 31358, 55087,
46356, 45228, 44406, 43521, 45501, 40281, 41091, 41681, 39266,
36268, 34754, 35341, 35943, 28852, 27810, 25186, 25501, 26232,
25775, 23698, 25314, 25960, 26259, 27487, 26966, 25817, 21294,
22704, 23997), ctr = c(0.0157890561813006, 0.0166396305077271,
0.0173986509381537, 0.0194731497951218, 0.0179954394804347, 0.01711863909483,
0.0181582360570687, 0.0171927115779559, 0.0172358403646591, 0.0174638541971058,
0.0178806664612045, 0.017462347179514, 0.0183790774089859, 0.0199881077619723,
0.0174426987635606, 0.021089685240109, 0.0205569049800296, 0.0177842661874661,
0.0173413941476575, 0.0169081718788632, 0.0182456430344012, 0.0182626162052032,
0.0182543279386951, 0.0186259961442581, 0.0170104683085926, 0.0171132003490177,
0.0171517774365777, 0.0170457664943143, 0.016903142521019, 0.0175382134561578,
0.0164120092891695, 0.0157969704536582, 0.014264557168488, 0.0143332034531726,
0.0152322825367764, 0.0147200846456646, 0.0152154800186776, 0.0140607309566817,
0.0137719608789332, 0.0122855439272407, 0.0119334194687182, 0.0125752060979989,
0.01158007808718, 0.0113191407332442, 0.00729059877222415, 0.00731911608538772,
0.0106771470535411, 0.029937936916542, 0.0143512493034839, 0.0146854166936255,
0.0149305898441825, 0.015325442746133, 0.015691446743994, 0.0144534643673336,
0.0147711815606066, 0.0158382630541111, 0.0148728508159624, 0.015102040564144,
0.0148955533969277, 0.0176392994824187, 0.0163240478169816, 0.0158230497930639,
0.0166871934499785, 0.0150557839107457, 0.0159453688844757, 0.0158074236363467,
0.0158454822084702, 0.0149292254566175, 0.0142730130593139, 0.0156929838274791,
0.0156162350209032, 0.0153802494466767, 0.0150476029799385, 0.015555365325721,
0.0143761174252573, 0.0154064275947974, 0.0208510166815324, 0.0176754346231314,
0.0176296702464377, 0.01808584587117, 0.0184482114318881, 0.0179540460804964,
0.0172054387638893, 0.0186435592467685, 0.0183226179107802, 0.0183442319676677,
0.0186738733252132, 0.0197702609494553, 0.0204285359857455, 0.0189093019186096,
0.0207614056972417, 0.0221922195760301, 0.00240617175649865,
0.00788575626634226, 0.01309841408011, 0.0157695717780358, 0.0156402333683254,
0.0162649757475833, 0.0155814665868539, 0.0165668899473124, 0.0162596037350689,
0.0168350415867981, 0.0154154128099543, 0.0150464847912372, 0.0161870630522126,
0.0156293605393382, 0.0166831626222356, 0.0159851624182969, 0.0181646017543342,
0.0154736802975027, 0.0147489845006063, 0.0172093148404027, 0.0173801189598905,
0.0179353887292393, 0.017586875624838, 0.0169123585500959, 0.0155822266067893,
0.0149761651657073, 0.0167448758587691, 0.0161082597966258, 0.0167303551270177,
0.0154917937591837, 0.015286011465188, 0.0136306070303869, 0.0152129210946259,
0.0159440585908669, 0.0161367409642245, 0.0164079686231546, 0.016492577386447,
0.0155465861608803, 0.0151072490270382, 0.0144004027929932, 0.0251766100192941,
0.0300583807652007, 0.0394582941939502, 0.0346703430162482, 0.0370259651104479,
0.0354306787130485, 0.0369234479028471, 0.0313956783546004, 0.0175071227813499,
0.0153811379243536, 0.0149988963637585, 0.0159494386911496, 0.0151254119566314,
0.0151138709885764, 0.0152175253675449, 0.015437458845637, 0.0147726989007463,
0.163043027137275, 0.0264129334017437, 0.0201436139554002, 0.0169325780144314,
0.0214876387664511, 0.0177445890793224, 0.0172606914733451, 0.017133563936406,
0.0185813515317095, 0.0180607614170281, 0.0187505760492009, 0.0169511102933927,
0.0178137558385877, 0.0184785698285323, 0.0201169476464591, 0.0220364679005246,
0.0212945438945016, 0.021660499704709, 0.0203399246100257, 0.021042755155702,
0.0207706911083365, 0.0191080416224264, 0.0188521002714409, 0.0176177277744931,
0.0170654092407268, 0.0167173964870618, 0.0169957130997929, 0.0173290930652611,
0.018723068602435, 0.0190819762151085, 0.0178334964691514, 0.0160768402598991,
0.0172883539665594, 0.0176745227466401)), row.names = c(NA, -183L
), class = "data.frame")

Related

Is there a way to create a dynamic regression model (ARIMAX) with multiple explanatory variables?

Is there a way to create a dynamic regression model (ARIMAX) with multiple explanatory variables?
The explanatory variables are introduced into the model with the regression part (xreg()).
(Fit <- auto.arima(Oct_Mar[, "ctr"],
                   xreg = Oct_Mar[, "price_purchase"]))`
As long as I use a variable it works to create the model.
As soon as I want to use several variables:
(Fit <- auto.arima(Oct_Mar[, "ctr"],
xreg = Oct_Mar[, "price_purchase"],
xreg = Oct_Mar[, "price_view"],
xreg = Oct_Mar[, "price_cart"]))`
Error:
Error in auto.arima(Oct_Mar[, "ctr"], xreg = Oct_Mar[, "price_purchase"], :
formal argument "xreg" matched by multiple actual arguments
When I try it like this:
(Fit <- auto.arima(Oct_Mar[, "ctr"],
xreg = Oct_Mar[, 2:6])) `
Error:
Error in auto.arima(Oct_Mar[, "ctr"], xreg = Oct_Mar[, 2:6]) :
xreg should be a numeric matrix or a numeric vector
All chosen variables should be numeric.
Data Subset:
structure(list(date = c("2019.10.01", "2019.10.02", "2019.10.03",
"2019.10.04", "2019.10.05", "2019.10.06", "2019.10.07", "2019.10.08",
"2019.10.09", "2019.10.10", "2019.10.11", "2019.10.12", "2019.10.13",
"2019.10.14", "2019.10.15", "2019.10.16", "2019.10.17", "2019.10.18",
"2019.10.19", "2019.10.20", "2019.10.21", "2019.10.22", "2019.10.23",
"2019.10.24", "2019.10.25", "2019.10.26", "2019.10.27", "2019.10.28",
"2019.10.29", "2019.10.30", "2019.10.31", "2019.11.01", "2019.11.02",
"2019.11.03", "2019.11.04", "2019.11.05", "2019.11.06", "2019.11.07",
"2019.11.08", "2019.11.09", "2019.11.10", "2019.11.11", "2019.11.12",
"2019.11.13", "2019.11.14", "2019.11.15", "2019.11.16", "2019.11.17",
"2019.11.18", "2019.11.19", "2019.11.20", "2019.11.21", "2019.11.22",
"2019.11.23", "2019.11.24", "2019.11.25", "2019.11.26", "2019.11.27",
"2019.11.28", "2019.11.29", "2019.11.30", "2019.12.01", "2019.12.02",
"2019.12.03", "2019.12.04", "2019.12.05", "2019.12.06", "2019.12.07",
"2019.12.08", "2019.12.09", "2019.12.10", "2019.12.11", "2019.12.12",
"2019.12.13", "2019.12.14", "2019.12.15", "2019.12.16", "2019.12.17",
"2019.12.18", "2019.12.19", "2019.12.20", "2019.12.21", "2019.12.22",
"2019.12.23", "2019.12.24", "2019.12.25", "2019.12.26", "2019.12.27",
"2019.12.28", "2019.12.29", "2019.12.30", "2019.12.31", "2020.01.01",
"2020.01.02", "2020.01.03", "2020.01.04", "2020.01.05", "2020.01.06",
"2020.01.07", "2020.01.08", "2020.01.09", "2020.01.10", "2020.01.11",
"2020.01.12", "2020.01.13", "2020.01.14", "2020.01.15", "2020.01.16",
"2020.01.17", "2020.01.18", "2020.01.19", "2020.01.20", "2020.01.21",
"2020.01.22", "2020.01.23", "2020.01.24", "2020.01.25", "2020.01.26",
"2020.01.27", "2020.01.28", "2020.01.29", "2020.01.30", "2020.01.31",
"2020.02.01", "2020.02.02", "2020.02.03", "2020.02.04", "2020.02.05",
"2020.02.06", "2020.02.07", "2020.02.08", "2020.02.09", "2020.02.10",
"2020.02.11", "2020.02.12", "2020.02.13", "2020.02.14", "2020.02.15",
"2020.02.16", "2020.02.17", "2020.02.18", "2020.02.19", "2020.02.20",
"2020.02.21", "2020.02.22", "2020.02.23", "2020.02.24", "2020.02.25",
"2020.02.26", "2020.02.27", "2020.02.28", "2020.02.29", "2020.03.01",
"2020.03.02", "2020.03.03", "2020.03.04", "2020.03.05", "2020.03.06",
"2020.03.07", "2020.03.08", "2020.03.09", "2020.03.10", "2020.03.11",
"2020.03.12", "2020.03.13", "2020.03.14", "2020.03.15", "2020.03.16",
"2020.03.17", "2020.03.18", "2020.03.19", "2020.03.20", "2020.03.21",
"2020.03.22", "2020.03.23", "2020.03.24", "2020.03.25", "2020.03.26",
"2020.03.27", "2020.03.28", "2020.03.29", "2020.03.30", "2020.03.31"
), price_view = c(35.79, 180.16, 437.57, 10.3, 74.26, 79.8, 89.84,
121.24, 461.95, 142.06, 241.71, 52, 43.24, 41.16, 167.05, 764.06,
91.64, 189.82, 38.59, 152.64, 86.23, 321.33, 411.83, 256.88,
352.39, 76.32, 360.11, 123.53, 43.41, 149.38, 14.16, 489.07,
1661.74, 1253.07, 25.71, 154.42, 990.89, 1645.93, 144.12, 84.43,
240.25, 148.18, 41.13, 262.56, 168.78, 860.85, 239.31, 372.98,
165.64, 134.32, 20.7, 43.73, 765.76, 51.48, 599.49, 893.79, 155.29,
334.37, 46.82, 1814.72, 196.27, 1302.48, 40.16, 1161.68, 381.48,
184.48, 48.91, 221.11, 434.73, 149.27, 77.22, 882.49, 106.05,
669.23, 282.86, 179.67, 12.97, 460.24, 38.59, 278.26, 243.76,
1904.79, 84.93, 32.18, 25.71, 496.54, 29.6, 1466.83, 164.33,
234.76, 19.95, 308.37, 1130.02, 7.47, 79.8, 65.9, 746.45, 1347.78,
1270.82, 69.42, 231.41, 195.6, 715.33, 208.47, 720.46, 414.68,
24.45, 217.82, 434.45, 483.92, 1500.42, 318.15, 339.29, 267.45,
133.85, 9.03, 11.81, 280.57, 916.74, 58.51, 339.78, 33.98, 263.58,
19.31, 239.88, 489.07, 84.92, 344.9, 95.24, 99.1, 142.58, 480.58,
104.74, 14.83, 252, 1039.41, 28.3, 328.97, 341.55, 278.26, 43.73,
91.35, 102.32, 131.25, 155.15, 77.74, 14.67, 132.63, 1185.36,
291.13, 1106.59, 849.42, 117.63, 171.32, 167.31, 252.23, 248.14,
111.15, 257.15, 27.62, 169.86, 101.89, 282.89, 298.57, 86.49,
196.32, 1415.45, 898.35, 334.6, 17.99, 13.62, 566.27, 60.41,
36.34, 62.04, 308.81, 32.95, 127.44, 836.57, 221.34, 360.34,
159.31, 20.57), view = c(1206151, 1152770, 1087372, 1344804,
1270060, 1262993, 1159265, 1323522, 1301376, 1240347, 1445162,
1432321, 1583572, 1376274, 1462409, 1443323, 1337174, 1413405,
1382403, 1443838, 1342668, 1353053, 1318395, 1252747, 1369922,
1288939, 1330209, 1220710, 1187883, 1169955, 1207854, 1402754,
1513400, 1524803, 1743304, 1670637, 1644359, 1748812, 1789808,
1783142, 1845552, 1907417, 1892753, 1920411, 2864410, 5691766,
5986292, 5759703, 1905351, 1627672, 1598554, 1573101, 1471242,
1474138, 1500022, 1496128, 1557252, 1547199, 1560191, 1727852,
1644405, 1706901, 1629904, 1547658, 1468085, 1540157, 1652208,
1725106, 1724452, 1627222, 1651328, 1605421, 1650612, 1634861,
1760750, 2167056, 2875847, 2780816, 2665285, 2528244, 2387520,
2340327, 2471739, 2372930, 2326654, 2322753, 2240514, 2058141,
2089081, 2474226, 2294820, 1603749, 1427733, 1700904, 1765457,
1754424, 1738774, 1696188, 1701769, 1585870, 1556542, 1557542,
1618230, 1645866, 1627433, 1612956, 1555416, 1773179, 1826768,
2021676, 2104199, 1801073, 1733142, 1593991, 1645225, 1557626,
1637470, 1721003, 1545472, 1594688, 1565742, 1651606, 1999670,
2217825, 1985751, 1680034, 1608904, 1620473, 1628906, 1726835,
1589058, 1714745, 1751044, 1896265, 2429526, 2268487, 1935249,
1916034, 2239698, 1916650, 1981570, 1948648, 1987134, 1749514,
1822349, 1830307, 1748590, 1734610, 1798308, 162557, 1000204,
1257475, 1770064, 2416707, 2477258, 2487470, 2457500, 2210539,
2377633, 2026050, 2301337, 2218894, 2012789, 1700619, 1481115,
1562027, 1560348, 1338829, 1244973, 1142989, 1260747, 1316975,
1387394, 1319559, 1440470, 1451015, 1439649, 1390411, 1336076,
1369834, 1255626, 1244163, 1283731), price_cart = c(29.51, 1415.48,
99.86, 358.57, 617.51, 1052.79, 1747.79, 190.56, 128.28, 252.38,
250.91, 720.48, 33.42, 643, 191.77, 460.11, 408.5, 789.9, 577.94,
49.36, 380.7, 19.56, 994.86, 756.71, 223.66, 437.33, 1684.28,
366.16, 968.34, 1683.07, 550.77, 503.09, 29.09, 179.67, 210.62,
22.66, 131.66, 68.96, 360.06, 494.22, 1023.62, 1569.92, 28.29,
694.97, 127.05, 37.85, 282.89, 178.9, 913.28, 1022.42, 424.7,
573.7, 1029.34, 30.12, 20.82, 17.99, 107.53, 41.19, 85.82, 1002.55,
140.98, 167.03, 231.67, 25.71, 205.64, 30.81, 51.22, 65.9, 7.08,
308.63, 227.79, 16.22, 7.89, 62.52, 48.88, 586.63, 602.07, 1312.26,
128.32, 179.9, 849.42, 100.9, 1284.2, 12.84, 128.42, 59.18, 176.99,
38.02, 48.88, 694.54, 262.3, 1402.84, 1453.18, 3.84, 453.01,
76.93, 7.04, 865.93, 865.4, 40.75, 1423.07, 1534.66, 679.27,
11.25, 102.63, 436.3, 853.93, 694.97, 850.47, 477.49, 1234.97,
10.27, 23.94, 643.23, 89.84, 290.34, 320.99, 6.44, 140.28, 188.89,
56.88, 1326.31, 194.34, 140.28, 771.96, 140.03, 20.21, 1464.39,
59.18, 57.92, 1156.81, 50.43, 300.12, 38.1, 832.71, 57.91, 174.5,
100.36, 248.14, 109.34, 100.7, 242.7, 266.67, 592.01, 242.18,
22.66, 566.04, 38.61, 812.06, 123.92, 168.6, 172.03, 49.91, 16.73,
108.04, 347.47, 97.79, 111.15, 514.79, 126.1, 178.87, 870.03,
529.31, 43.5, 2110.48, 771.94, 15.32, 105.25, 7.14, 312.67, 61.75,
165.51, 48.37, 643.49, 303.48, 35.78, 154.42, 209.71, 76.69,
25.46, 1415.45, 123.53, 602.31), cart = c(16658, 17268, 19323,
43826, 35493, 32145, 18052, 18442, 18432, 18997, 21450, 20691,
24833, 44821, 49513, 45272, 40368, 40127, 39455, 40533, 36675,
36945, 36407, 35721, 36800, 34776, 34256, 17838, 17455, 16996,
16798, 18911, 19350, 20211, 21960, 19231, 19670, 19446, 77319,
70093, 71585, 75135, 69669, 71613, 170183, 481862, 405584, 426261,
83117, 72450, 72311, 75530, 70171, 64801, 68099, 71405, 71622,
71324, 71504, 92345, 81760, 84473, 80869, 70192, 66718, 71048,
83618, 84231, 80773, 80675, 81420, 78947, 80162, 82360, 86689,
109721, 183764, 155406, 146906, 137487, 127900, 124577, 127381,
126700, 124797, 127554, 123966, 120940, 127769, 148663, 148608,
119062, 57614, 71342, 95608, 80629, 78782, 79099, 77396, 74671,
72772, 74827, 72221, 73406, 72999, 71182, 70235, 79414, 104791,
103481, 102597, 94354, 90666, 83642, 83223, 73075, 73582, 73849,
70067, 71600, 72179, 130757, 208231, 169156, 137970, 116560,
104701, 102836, 101145, 101605, 90864, 92635, 95114, 100283,
158447, 131720, 118661, 126405, 132399, 98277, 96270, 95284,
96886, 89046, 91384, 89585, 83771, 83241, 84151, 6104, 40574,
48944, 81869, 146953, 135144, 132819, 134255, 131648, 141696,
122204, 122752, 120927, 112159, 102239, 95998, 97600, 99032,
79662, 76622, 69585, 73822, 74488, 75621, 69098, 73761, 76429,
75664, 77671, 77090, 77835, 68888, 69091, 73986), price_purchase = c(130.76,
419.6, 251.74, 252.88, 64.02, 272.59, 172.72, 88.81, 28.73, 1003.86,
346.47, 130.48, 29.86, 280.11, 358.57, 385.83, 287.61, 22.95,
58.08, 854.08, 28.28, 62.91, 994.86, 51.22, 9.01, 77.21, 244.15,
366.16, 366.8, 213.25, 35.52, 566.3, 35.78, 1106.82, 64.35, 722.18,
131.66, 166.1, 823.9, 138.23, 334.6, 328.19, 243.51, 488.8, 159.57,
106.8, 54.03, 27, 308.63, 1022.42, 463.31, 144.66, 44.53, 25.48,
126.18, 365.52, 133.92, 97.27, 12.84, 1002.55, 107.41, 132.31,
131.2, 789.57, 230.2, 12.36, 229.86, 1386.91, 154.19, 18.19,
76.96, 882.49, 191.55, 46.08, 24.17, 102.65, 326.62, 924.06,
923.73, 88.29, 41.16, 128.42, 326.88, 137.96, 30.68, 108.88,
181.19, 241.34, 128.32, 137.46, 1279.81, 643.23, 1275.16, 717.245,
159.33, 745.37, 288.27, 177.26, 168.58, 66.85, 331.51, 437.31,
643.23, 9.3, 0.85, 436.3, 105.51, 7.7, 79.44, 1321.37, 160.89,
107.21, 172.25, 514.79, 141.06, 900.64, 153.22, 924.4, 176.34,
94.98, 162.6, 1326.25, 39.9, 38.15, 2162.22, 180.95, 153.41,
720.48, 720.48, 15.42, 140.28, 514.02, 720.47, 174.7, 197.69,
411.08, 741.07, 230.12, 501.89, 109.34, 643.26, 23.17, 242.48,
1317.36, 69.76, 178.11, 153.55, 32.18, 812.06, 302.2, 153.34,
172.03, 128.68, 939.54, 108.04, 165.89, 56.63, 43.76, 171.17,
98.59, 21.95, 280.28, 181.47, 730.01, 159.31, 60.75, 31.15, 1412.39,
7.14, 942.84, 321.06, 165.51, 284.95, 169.42, 303.48, 224.3,
416.43, 385.85, 492.08, 334.6, 1415.45, 123.53, 308.55), purchase = c(19307,
19469, 19255, 27041, 23494, 22171, 21378, 23072, 22748, 21993,
26224, 25373, 29561, 28405, 26372, 31394, 28318, 25850, 24657,
25098, 25167, 25385, 24731, 23999, 23929, 22653, 23403, 21112,
20374, 20817, 20099, 22458, 21864, 22145, 26889, 24875, 25319,
24863, 25714, 22768, 22878, 24931, 22725, 22548, 22124, 45185.5,
68247, 185195, 28537, 24967, 24947, 25266, 24187, 22243, 23163,
24827, 24226, 24443, 24305, 32107, 28178, 28345, 28548, 24358,
24473, 25469, 27505, 27012, 25766, 26802, 27059, 25906, 26044,
26712, 26559, 35077, 63796, 51899, 49578, 48212, 46405, 44255,
44719, 46602, 44917, 44949, 44154, 43081, 45287, 49597, 50729,
38233, 3574, 13975.5, 24377, 28938, 28427, 28875, 27722, 27510,
26492, 27481, 26059, 25869, 27525, 26322, 27121, 29614, 35086,
32884, 32548, 32619, 31698, 30089, 30398, 27579, 26662, 26880,
27052, 26841, 27403, 27612, 33750, 32536, 32308, 28645, 27652,
28276, 28533, 28426, 25379, 26027, 46480, 60013, 102117, 83216,
76048, 72365, 87586, 63260, 36377, 31438, 31258, 29324, 28946,
29017, 27884, 28063, 27809, 27499, 27490, 26316, 31358, 55087,
46356, 45228, 44406, 43521, 45501, 40281, 41091, 41681, 39266,
36268, 34754, 35341, 35943, 28852, 27810, 25186, 25501, 26232,
25775, 23698, 25314, 25960, 26259, 27487, 26966, 25817, 21294,
22704, 23997), ctr = c(0.0157890561813006, 0.0166396305077271,
0.0173986509381537, 0.0194731497951218, 0.0179954394804347, 0.01711863909483,
0.0181582360570687, 0.0171927115779559, 0.0172358403646591, 0.0174638541971058,
0.0178806664612045, 0.017462347179514, 0.0183790774089859, 0.0199881077619723,
0.0174426987635606, 0.021089685240109, 0.0205569049800296, 0.0177842661874661,
0.0173413941476575, 0.0169081718788632, 0.0182456430344012, 0.0182626162052032,
0.0182543279386951, 0.0186259961442581, 0.0170104683085926, 0.0171132003490177,
0.0171517774365777, 0.0170457664943143, 0.016903142521019, 0.0175382134561578,
0.0164120092891695, 0.0157969704536582, 0.014264557168488, 0.0143332034531726,
0.0152322825367764, 0.0147200846456646, 0.0152154800186776, 0.0140607309566817,
0.0137719608789332, 0.0122855439272407, 0.0119334194687182, 0.0125752060979989,
0.01158007808718, 0.0113191407332442, 0.00729059877222415, 0.00731911608538772,
0.0106771470535411, 0.029937936916542, 0.0143512493034839, 0.0146854166936255,
0.0149305898441825, 0.015325442746133, 0.015691446743994, 0.0144534643673336,
0.0147711815606066, 0.0158382630541111, 0.0148728508159624, 0.015102040564144,
0.0148955533969277, 0.0176392994824187, 0.0163240478169816, 0.0158230497930639,
0.0166871934499785, 0.0150557839107457, 0.0159453688844757, 0.0158074236363467,
0.0158454822084702, 0.0149292254566175, 0.0142730130593139, 0.0156929838274791,
0.0156162350209032, 0.0153802494466767, 0.0150476029799385, 0.015555365325721,
0.0143761174252573, 0.0154064275947974, 0.0208510166815324, 0.0176754346231314,
0.0176296702464377, 0.01808584587117, 0.0184482114318881, 0.0179540460804964,
0.0172054387638893, 0.0186435592467685, 0.0183226179107802, 0.0183442319676677,
0.0186738733252132, 0.0197702609494553, 0.0204285359857455, 0.0189093019186096,
0.0207614056972417, 0.0221922195760301, 0.00240617175649865,
0.00788575626634226, 0.01309841408011, 0.0157695717780358, 0.0156402333683254,
0.0162649757475833, 0.0155814665868539, 0.0165668899473124, 0.0162596037350689,
0.0168350415867981, 0.0154154128099543, 0.0150464847912372, 0.0161870630522126,
0.0156293605393382, 0.0166831626222356, 0.0159851624182969, 0.0181646017543342,
0.0154736802975027, 0.0147489845006063, 0.0172093148404027, 0.0173801189598905,
0.0179353887292393, 0.017586875624838, 0.0169123585500959, 0.0155822266067893,
0.0149761651657073, 0.0167448758587691, 0.0161082597966258, 0.0167303551270177,
0.0154917937591837, 0.015286011465188, 0.0136306070303869, 0.0152129210946259,
0.0159440585908669, 0.0161367409642245, 0.0164079686231546, 0.016492577386447,
0.0155465861608803, 0.0151072490270382, 0.0144004027929932, 0.0251766100192941,
0.0300583807652007, 0.0394582941939502, 0.0346703430162482, 0.0370259651104479,
0.0354306787130485, 0.0369234479028471, 0.0313956783546004, 0.0175071227813499,
0.0153811379243536, 0.0149988963637585, 0.0159494386911496, 0.0151254119566314,
0.0151138709885764, 0.0152175253675449, 0.015437458845637, 0.0147726989007463,
0.163043027137275, 0.0264129334017437, 0.0201436139554002, 0.0169325780144314,
0.0214876387664511, 0.0177445890793224, 0.0172606914733451, 0.017133563936406,
0.0185813515317095, 0.0180607614170281, 0.0187505760492009, 0.0169511102933927,
0.0178137558385877, 0.0184785698285323, 0.0201169476464591, 0.0220364679005246,
0.0212945438945016, 0.021660499704709, 0.0203399246100257, 0.021042755155702,
0.0207706911083365, 0.0191080416224264, 0.0188521002714409, 0.0176177277744931,
0.0170654092407268, 0.0167173964870618, 0.0169957130997929, 0.0173290930652611,
0.018723068602435, 0.0190819762151085, 0.0178334964691514, 0.0160768402598991,
0.0172883539665594, 0.0176745227466401)), row.names = c(NA, -183L
), class = "data.frame")
As the error explains, xreg should be a numeric matrix, not a data frame. The following works.
Fit <- auto.arima(Oct_Mar[, "ctr"], xreg = as.matrix(Oct_Mar[, 2:6]))

i need to find the coordinated of the peaks as well as delineate their boundaries (i.e. peak 1 begins at time 65 and ends at time 71)

import numpy, sys
from matplotlib import pyplot
from scipy.signal import find_peaks, peak_widths
t=[0.0, 0.187, 0.373, 0.56, 0.747, 0.933, 1.12, 1.307, 1.493, 1.68, 1.867, 2.053, 2.24, 2.427, 2.613, 2.8, 2.987, 3.173, 3.36, 3.547, 3.733, 3.92, 4.107, 4.293, 4.48, 4.667, 4.853, 5.04, 5.227, 5.413, 5.6, 5.787, 5.973, 6.16, 6.347, 6.533, 6.72, 6.907, 7.093, 7.28, 7.467, 7.653, 7.84, 8.027, 8.213, 8.4, 8.587, 8.773, 8.96, 9.147, 9.333, 9.52, 9.707, 9.893, 10.08, 10.267, 10.453, 10.64, 10.827, 11.013, 11.2, 11.387, 11.573, 11.76, 11.947, 12.133, 12.32, 12.507, 12.693, 12.88, 13.067, 13.253, 13.44, 13.627, 13.813, 14.0, 14.187, 14.373, 14.56, 14.747, 14.933, 15.12, 15.307, 15.493, 15.68, 15.867, 16.053, 16.24, 16.427, 16.613, 16.8, 16.987, 17.173, 17.36, 17.547, 17.733, 17.92, 18.107, 18.293, 18.48, 18.667, 18.853, 19.04, 19.227, 19.413, 19.6, 19.787, 19.973, 20.16, 20.347, 20.533, 20.72, 20.907, 21.093, 21.28, 21.467, 21.653, 21.84, 22.027, 22.213, 22.4, 22.587, 22.773, 22.96, 23.147, 23.333, 23.52, 23.707, 23.893, 24.08, 24.267, 24.453, 24.64, 24.827, 25.013, 25.2, 25.387, 25.573, 25.76, 25.947, 26.133, 26.32, 26.507, 26.693, 26.88, 27.067, 27.253, 27.44, 27.627, 27.813, 28.0, 28.187, 28.373, 28.56, 28.747, 28.933, 29.12, 29.307, 29.493, 29.68, 29.867, 30.053, 30.24, 30.427, 30.613, 30.8, 30.987, 31.173, 31.36, 31.547, 31.733, 31.92, 32.107, 32.293, 32.48, 32.667, 32.853, 33.04, 33.227, 33.413, 33.6, 33.787, 33.973, 34.16, 34.347, 34.533, 34.72, 34.907, 35.093, 35.28, 35.467, 35.653, 35.84, 36.027, 36.213, 36.4, 36.587, 36.773, 36.96, 37.147, 37.333, 37.52, 37.707, 37.893, 38.08, 38.267, 38.453, 38.64, 38.827, 39.013, 39.2, 39.387, 39.573, 39.76, 39.947, 40.133, 40.32, 40.507, 40.693, 40.88, 41.067, 41.253, 41.44, 41.627, 41.813, 42.0, 42.187, 42.373, 42.56, 42.747, 42.933, 43.12, 43.307, 43.493, 43.68, 43.867, 44.053, 44.24, 44.427, 44.613, 44.8, 44.987, 45.173, 45.36, 45.547, 45.733, 45.92, 46.107, 46.293, 46.48, 46.667, 46.853, 47.04, 47.227, 47.413, 47.6, 47.787, 47.973, 48.16, 48.347, 48.533, 48.72, 48.907, 49.093, 49.28, 49.467, 49.653, 49.84, 50.027, 50.213, 50.4, 50.587, 50.773, 50.96, 51.147, 51.333, 51.52, 51.707, 51.893, 52.08, 52.267, 52.453, 52.64, 52.827, 53.013, 53.2, 53.387, 53.573, 53.76, 53.947, 54.133, 54.32, 54.507, 54.693, 54.88, 55.067, 55.253, 55.44, 55.627, 55.813, 56.0, 56.187, 56.373, 56.56, 56.747, 56.933, 57.12, 57.307, 57.493, 57.68, 57.867, 58.053, 58.24, 58.427, 58.613, 58.8, 58.987, 59.173, 59.36, 59.547, 59.733, 59.92, 60.107, 60.293, 60.48, 60.667, 60.853, 61.04, 61.227, 61.413, 61.6, 61.787, 61.973, 62.16, 62.347, 62.533, 62.72, 62.907, 63.093, 63.28, 63.467, 63.653, 63.84, 64.027, 64.213, 64.4, 64.587, 64.773, 64.96, 65.147, 65.333, 65.52, 65.707, 65.893, 66.08, 66.267, 66.453, 66.64, 66.827, 67.013, 67.2, 67.387, 67.573, 67.76, 67.947, 68.133, 68.32, 68.507, 68.693, 68.88, 69.067, 69.253, 69.44, 69.627, 69.813, 70.0, 70.187, 70.373, 70.56, 70.747, 70.933, 71.12, 71.307, 71.493, 71.68, 71.867, 72.053, 72.24, 72.427, 72.613, 72.8, 72.987, 73.173, 73.36, 73.547, 73.733, 73.92, 74.107, 74.293, 74.48, 74.667, 74.853, 75.04, 75.227, 75.413, 75.6, 75.787, 75.973, 76.16, 76.347, 76.533, 76.72, 76.907, 77.093, 77.28, 77.467, 77.653, 77.84, 78.027, 78.213, 78.4, 78.587, 78.773, 78.96, 79.147, 79.333, 79.52, 79.707, 79.893, 80.08, 80.267, 80.453, 80.64, 80.827, 81.013, 81.2, 81.387, 81.573, 81.76, 81.947, 82.133, 82.32, 82.507, 82.693, 82.88, 83.067, 83.253, 83.44, 83.627, 83.813, 84.0, 84.187, 84.373, 84.56, 84.747, 84.933, 85.12, 85.307, 85.493, 85.68, 85.867, 86.053, 86.24, 86.427, 86.613, 86.8, 86.987, 87.173, 87.36, 87.547, 87.733, 87.92, 88.107, 88.293, 88.48, 88.667, 88.853, 89.04, 89.227, 89.413, 89.6, 89.787, 89.973, 90.16, 90.347, 90.533, 90.72, 90.907, 91.093, 91.28, 91.467, 91.653, 91.84, 92.027, 92.213, 92.4, 92.587, 92.773, 92.96, 93.147, 93.333, 93.52, 93.707, 93.893, 94.08, 94.267, 94.453, 94.64, 94.827, 95.013, 95.2, 95.387, 95.573, 95.76, 95.947, 96.133, 96.32, 96.507, 96.693, 96.88, 97.067, 97.253, 97.44, 97.627, 97.813, 98.0, 98.187, 98.373, 98.56, 98.747, 98.933, 99.12, 99.307, 99.493, 99.68, 99.867, 100.053, 100.24, 100.427, 100.613, 100.8, 100.987, 101.173, 101.36, 101.547, 101.733, 101.92, 102.107, 102.293, 102.48, 102.667, 102.853, 103.04, 103.227, 103.413, 103.6, 103.787, 103.973, 104.16, 104.347, 104.533, 104.72, 104.907, 105.093, 105.28, 105.467, 105.653, 105.84, 106.027, 106.213, 106.4, 106.587, 106.773, 106.96, 107.147, 107.333, 107.52, 107.707, 107.893, 108.08, 108.267, 108.453, 108.64, 108.827, 109.013, 109.2, 109.387, 109.573, 109.76, 109.947, 110.133, 110.32, 110.507, 110.693, 110.88, 111.067, 111.253, 111.44, 111.627, 111.813, 112.0, 112.187, 112.373, 112.56, 112.747, 112.933, 113.12, 113.307, 113.493, 113.68, 113.867, 114.053, 114.24, 114.427, 114.613, 114.8, 114.987, 115.173, 115.36, 115.547, 115.733, 115.92, 116.107, 116.293, 116.48, 116.667, 116.853, 117.04, 117.227, 117.413, 117.6, 117.787, 117.973, 118.16, 118.347, 118.533, 118.72, 118.907, 119.093, 119.28, 119.467, 119.653, 119.84, 120.027, 120.213, 120.4, 120.587, 120.773, 120.96, 121.147, 121.333, 121.52, 121.707, 121.893, 122.08, 122.267, 122.453, 122.64, 122.827, 123.013, 123.2, 123.387, 123.573, 123.76, 123.947, 124.133, 124.32, 124.507, 124.693, 124.88, 125.067, 125.253, 125.44, 125.627, 125.813, 126.0, 126.187, 126.373, 126.56, 126.747, 126.933, 127.12, 127.307, 127.493, 127.68, 127.867, 128.053, 128.24, 128.427, 128.613, 128.8, 128.987, 129.173, 129.36, 129.547, 129.733, 129.92, 130.107, 130.293, 130.48, 130.667, 130.853, 131.04, 131.227, 131.413, 131.6, 131.787, 131.973, 132.16, 132.347, 132.533, 132.72, 132.907, 133.093, 133.28, 133.467, 133.653, 133.84, 134.027, 134.213, 134.4, 134.587, 134.773, 134.96, 135.147, 135.333, 135.52, 135.707, 135.893, 136.08, 136.267, 136.453, 136.64, 136.827, 137.013, 137.2, 137.387, 137.573, 137.76, 137.947, 138.133, 138.32, 138.507, 138.693, 138.88, 139.067, 139.253, 139.44, 139.627, 139.813, 140.0, 140.187, 140.373, 140.56, 140.747, 140.933, 141.12, 141.307, 141.493, 141.68, 141.867, 142.053, 142.24, 142.427, 142.613, 142.8, 142.987, 143.173, 143.36, 143.547, 143.733, 143.92, 144.107, 144.293, 144.48, 144.667, 144.853, 145.04, 145.227, 145.413, 145.6, 145.787, 145.973, 146.16, 146.347, 146.533, 146.72, 146.907, 147.093, 147.28, 147.467, 147.653, 147.84, 148.027, 148.213, 148.4, 148.587, 148.773, 148.96, 149.147, 149.333, 149.52, 149.707, 149.893, 150.08, 150.267, 150.453, 150.64, 150.827, 151.013, 151.2, 151.387, 151.573, 151.76, 151.947, 152.133, 152.32, 152.507, 152.693, 152.88, 153.067, 153.253, 153.44, 153.627, 153.813, 154.0, 154.187, 154.373, 154.56, 154.747, 154.933, 155.12, 155.307, 155.493, 155.68, 155.867, 156.053, 156.24, 156.427, 156.613, 156.8, 156.987, 157.173, 157.36, 157.547, 157.733, 157.92, 158.107, 158.293, 158.48, 158.667, 158.853, 159.04, 159.227, 159.413, 159.6, 159.787, 159.973, 160.16, 160.347, 160.533, 160.72, 160.907, 161.093, 161.28, 161.467, 161.653, 161.84, 162.027, 162.213, 162.4, 162.587, 162.773, 162.96, 163.147, 163.333, 163.52, 163.707, 163.893, 164.08, 164.267]
a= [0.0, 0.187, 0.373, 0.56, 0.747, 0.933, 1.12, 1.307, 1.493, 1.68, 1.867, 2.053, 2.24, 2.427, 2.613, 2.8, 2.987, 3.173, 3.36, 3.547, 3.733, 3.92, 4.107, 4.293, 4.48, 4.667, 4.853, 5.04, 5.227, 5.413, 5.6, 5.787, 5.973, 6.16, 6.347, 6.533, 6.72, 6.907, 7.093, 7.28, 7.467, 7.653, 7.84, 8.027, 8.213, 8.4, 8.587, 8.773, 8.96, 9.147, 9.333, 9.52, 9.707, 9.893, 10.08, 10.267, 10.453, 10.64, 10.827, 11.013, 11.2, 11.387, 11.573, 11.76, 11.947, 12.133, 12.32, 12.507, 12.693, 12.88, 13.067, 13.253, 13.44, 13.627, 13.813, 14.0, 14.187, 14.373, 14.56, 14.747, 14.933, 15.12, 15.307, 15.493, 15.68, 15.867, 16.053, 16.24, 16.427, 16.613, 16.8, 16.987, 17.173, 17.36, 17.547, 17.733, 17.92, 18.107, 18.293, 18.48, 18.667, 18.853, 19.04, 19.227, 19.413, 19.6, 19.787, 19.973, 20.16, 20.347, 20.533, 20.72, 20.907, 21.093, 21.28, 21.467, 21.653, 21.84, 22.027, 22.213, 22.4, 22.587, 22.773, 22.96, 23.147, 23.333, 23.52, 23.707, 23.893, 24.08, 24.267, 24.453, 24.64, 24.827, 25.013, 25.2, 25.387, 25.573, 25.76, 25.947, 26.133, 26.32, 26.507, 26.693, 26.88, 27.067, 27.253, 27.44, 27.627, 27.813, 28.0, 28.187, 28.373, 28.56, 28.747, 28.933, 29.12, 29.307, 29.493, 29.68, 29.867, 30.053, 30.24, 30.427, 30.613, 30.8, 30.987, 31.173, 31.36, 31.547, 31.733, 31.92, 32.107, 32.293, 32.48, 32.667, 32.853, 33.04, 33.227, 33.413, 33.6, 33.787, 33.973, 34.16, 34.347, 34.533, 34.72, 34.907, 35.093, 35.28, 35.467, 35.653, 35.84, 36.027, 36.213, 36.4, 36.587, 36.773, 36.96, 37.147, 37.333, 37.52, 37.707, 37.893, 38.08, 38.267, 38.453, 38.64, 38.827, 39.013, 39.2, 39.387, 39.573, 39.76, 39.947, 40.133, 40.32, 40.507, 40.693, 40.88, 41.067, 41.253, 41.44, 41.627, 41.813, 42.0, 42.187, 42.373, 42.56, 42.747, 42.933, 43.12, 43.307, 43.493, 43.68, 43.867, 44.053, 44.24, 44.427, 44.613, 44.8, 44.987, 45.173, 45.36, 45.547, 45.733, 45.92, 46.107, 46.293, 46.48, 46.667, 46.853, 47.04, 47.227, 47.413, 47.6, 47.787, 47.973, 48.16, 48.347, 48.533, 48.72, 48.907, 49.093, 49.28, 49.467, 49.653, 49.84, 50.027, 50.213, 50.4, 50.587, 50.773, 50.96, 51.147, 51.333, 51.52, 51.707, 51.893, 52.08, 52.267, 52.453, 52.64, 52.827, 53.013, 53.2, 53.387, 53.573, 53.76, 53.947, 54.133, 54.32, 54.507, 54.693, 54.88, 55.067, 55.253, 55.44, 55.627, 55.813, 56.0, 56.187, 56.373, 56.56, 56.747, 56.933, 57.12, 57.307, 57.493, 57.68, 57.867, 58.053, 58.24, 58.427, 58.613, 58.8, 58.987, 59.173, 59.36, 59.547, 59.733, 59.92, 60.107, 60.293, 60.48, 60.667, 60.853, 61.04, 61.227, 61.413, 61.6, 61.787, 61.973, 62.16, 62.347, 62.533, 62.72, 62.907, 63.093, 63.28, 63.467, 63.653, 63.84, 64.027, 64.213, 64.4, 64.587, 64.773, 64.96, 65.147, 65.333, 65.52, 65.707, 65.893, 66.08, 66.267, 66.453, 66.64, 66.827, 67.013, 67.2, 67.387, 67.573, 67.76, 67.947, 68.133, 68.32, 68.507, 68.693, 68.88, 69.067, 69.253, 69.44, 69.627, 69.813, 70.0, 70.187, 70.373, 70.56, 70.747, 70.933, 71.12, 71.307, 71.493, 71.68, 71.867, 72.053, 72.24, 72.427, 72.613, 72.8, 72.987, 73.173, 73.36, 73.547, 73.733, 73.92, 74.107, 74.293, 74.48, 74.667, 74.853, 75.04, 75.227, 75.413, 75.6, 75.787, 75.973, 76.16, 76.347, 76.533, 76.72, 76.907, 77.093, 77.28, 77.467, 77.653, 77.84, 78.027, 78.213, 78.4, 78.587, 78.773, 78.96, 79.147, 79.333, 79.52, 79.707, 79.893, 80.08, 80.267, 80.453, 80.64, 80.827, 81.013, 81.2, 81.387, 81.573, 81.76, 81.947, 82.133, 82.32, 82.507, 82.693, 82.88, 83.067, 83.253, 83.44, 83.627, 83.813, 84.0, 84.187, 84.373, 84.56, 84.747, 84.933, 85.12, 85.307, 85.493, 85.68, 85.867, 86.053, 86.24, 86.427, 86.613, 86.8, 86.987, 87.173, 87.36, 87.547, 87.733, 87.92, 88.107, 88.293, 88.48, 88.667, 88.853, 89.04, 89.227, 89.413, 89.6, 89.787, 89.973, 90.16, 90.347, 90.533, 90.72, 90.907, 91.093, 91.28, 91.467, 91.653, 91.84, 92.027, 92.213, 92.4, 92.587, 92.773, 92.96, 93.147, 93.333, 93.52, 93.707, 93.893, 94.08, 94.267, 94.453, 94.64, 94.827, 95.013, 95.2, 95.387, 95.573, 95.76, 95.947, 96.133, 96.32, 96.507, 96.693, 96.88, 97.067, 97.253, 97.44, 97.627, 97.813, 98.0, 98.187, 98.373, 98.56, 98.747, 98.933, 99.12, 99.307, 99.493, 99.68, 99.867, 100.053, 100.24, 100.427, 100.613, 100.8, 100.987, 101.173, 101.36, 101.547, 101.733, 101.92, 102.107, 102.293, 102.48, 102.667, 102.853, 103.04, 103.227, 103.413, 103.6, 103.787, 103.973, 104.16, 104.347, 104.533, 104.72, 104.907, 105.093, 105.28, 105.467, 105.653, 105.84, 106.027, 106.213, 106.4, 106.587, 106.773, 106.96, 107.147, 107.333, 107.52, 107.707, 107.893, 108.08, 108.267, 108.453, 108.64, 108.827, 109.013, 109.2, 109.387, 109.573, 109.76, 109.947, 110.133, 110.32, 110.507, 110.693, 110.88, 111.067, 111.253, 111.44, 111.627, 111.813, 112.0, 112.187, 112.373, 112.56, 112.747, 112.933, 113.12, 113.307, 113.493, 113.68, 113.867, 114.053, 114.24, 114.427, 114.613, 114.8, 114.987, 115.173, 115.36, 115.547, 115.733, 115.92, 116.107, 116.293, 116.48, 116.667, 116.853, 117.04, 117.227, 117.413, 117.6, 117.787, 117.973, 118.16, 118.347, 118.533, 118.72, 118.907, 119.093, 119.28, 119.467, 119.653, 119.84, 120.027, 120.213, 120.4, 120.587, 120.773, 120.96, 121.147, 121.333, 121.52, 121.707, 121.893, 122.08, 122.267, 122.453, 122.64, 122.827, 123.013, 123.2, 123.387, 123.573, 123.76, 123.947, 124.133, 124.32, 124.507, 124.693, 124.88, 125.067, 125.253, 125.44, 125.627, 125.813, 126.0, 126.187, 126.373, 126.56, 126.747, 126.933, 127.12, 127.307, 127.493, 127.68, 127.867, 128.053, 128.24, 128.427, 128.613, 128.8, 128.987, 129.173, 129.36, 129.547, 129.733, 129.92, 130.107, 130.293, 130.48, 130.667, 130.853, 131.04, 131.227, 131.413, 131.6, 131.787, 131.973, 132.16, 132.347, 132.533, 132.72, 132.907, 133.093, 133.28, 133.467, 133.653, 133.84, 134.027, 134.213, 134.4, 134.587, 134.773, 134.96, 135.147, 135.333, 135.52, 135.707, 135.893, 136.08, 136.267, 136.453, 136.64, 136.827, 137.013, 137.2, 137.387, 137.573, 137.76, 137.947, 138.133, 138.32, 138.507, 138.693, 138.88, 139.067, 139.253, 139.44, 139.627, 139.813, 140.0, 140.187, 140.373, 140.56, 140.747, 140.933, 141.12, 141.307, 141.493, 141.68, 141.867, 142.053, 142.24, 142.427, 142.613, 142.8, 142.987, 143.173, 143.36, 143.547, 143.733, 143.92, 144.107, 144.293, 144.48, 144.667, 144.853, 145.04, 145.227, 145.413, 145.6, 145.787, 145.973, 146.16, 146.347, 146.533, 146.72, 146.907, 147.093, 147.28, 147.467, 147.653, 147.84, 148.027, 148.213, 148.4, 148.587, 148.773, 148.96, 149.147, 149.333, 149.52, 149.707, 149.893, 150.08, 150.267, 150.453, 150.64, 150.827, 151.013, 151.2, 151.387, 151.573, 151.76, 151.947, 152.133, 152.32, 152.507, 152.693, 152.88, 153.067, 153.253, 153.44, 153.627, 153.813, 154.0, 154.187, 154.373, 154.56, 154.747, 154.933, 155.12, 155.307, 155.493, 155.68, 155.867, 156.053, 156.24, 156.427, 156.613, 156.8, 156.987, 157.173, 157.36, 157.547, 157.733, 157.92, 158.107, 158.293, 158.48, 158.667, 158.853, 159.04, 159.227, 159.413, 159.6, 159.787, 159.973, 160.16, 160.347, 160.533, 160.72, 160.907, 161.093, 161.28, 161.467, 161.653, 161.84, 162.027, 162.213, 162.4, 162.587, 162.773, 162.96, 163.147, 163.333, 163.52, 163.707, 163.893, 164.08, 164.267]
a=numpy.array(a)
t=numpy.array(t)
mean = numpy.mean(a)
std = numpy.std(a)
peaks, _ = find_peaks(a,prominence=1)
pyplot.plot(a)
pyplot.plot(peaks,a[peaks],"o")
plot

How to check if a record already exists or not in database in DRF?

I am working on DRF. I am creating an API of POST request that overriding its features. I want to add one functionality if a particular field value already exists in DB then, user cannot create post request and instead of it getting a message that he couldn't do it.
views.py
class PizzaOrderViewSet(viewsets.ModelViewSet):
http_method_names = ['get', 'put', 'patch', 'post']
def create(self, request, *args, **kwargs):
data = request.data
order = PizzaOrder.objects.create(
name=data['name'], flavours=data['flavours'],
number=data['number'], size=data['size'],
customer_name=data['customer_name'],
customer_address=data['customer_address']
)
order.save()
serializer = PizzaOrderSerializer(order)
return Response(serializer.data)
serializers.py
class PizzaOrderSerializer(serializers.ModelSerializer):
class Meta:
model = PizzaOrder
validators = [
UniqueTogetherValidator(
queryset=PizzaOrder.objects.all(),
fields=['name', 'flavours', 'size', 'customer_name', 'customer_address'],
message='This field should be unique'
)
]
models.py
from django.db import models
from datetime import datetime
FLAVOURS_CHOICE = (
('Margarita', 'Margarita'),
('Marinara', 'Marinara'),
('Salami', 'Salami'),
)
SIZE_CHOICE = (
('Small', 'Small'),
('Medium', 'Medium'),
('Large', 'Large'),
)
STATUS_CHOICE = (
('Open', 'Open'),
('Accepted', 'Accepted'),
('Preparing', 'Preparing'),
('OnWay', 'OnWay'),
('Delivered', 'Delivered'),
)
class PizzaOrder(models.Model):
name = models.CharField(max_length=50, blank=False)
flavours = models.CharField(max_length=20, choices=FLAVOURS_CHOICE)
quantity = models.IntegerField()
size = models.CharField(max_length=10, choices=SIZE_CHOICE)
customer_name = models.CharField(max_length=30, blank=False)
customer_address = models.TextField(blank=False)
ordered_time = models.DateTimeField(default=datetime.now, editable=False)
status = models.CharField(max_length=20, choices=STATUS_CHOICE, default='Open')
def __str__(self):
return self.name
class Meta:
ordering = ['-ordered_time']
unique_together = ('name', 'flavours', 'quantity', 'size')
How could I achieve this?

How can I add From date to To date to print a set of records in report in odoo 10?

I am creating a Bank module, where the customers can buy loans from the bank. In that I want to print a report statement. Before printing the records of a particular customer, i want to filter the dates. I want to filter it by giving From date to To date. So the loan amounts where the customer bought from the bank in that given dates should print.
Thank You,
Hope I will gain some knowledge.
below code for wizard
class BankCustomer(models.TransientModel):
_name = 'bank.customer'
_description = 'Bank Customer Report'
date_from = fields.Date(string='From date', required=True,default=lambda *a: time.strftime('%Y-%m-01'))
date_to = fields.Date(string='To date', required=True,default=lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10])
#api.multi
def pdf_bank_customer_report(self):
data = self.read()[0]
datas = {
'ids': [],
'model': 'bank.customer',
'form': data
}
return self.env['report'].with_context(landscape=True).get_action(self, 'module_name.template_name', data=datas)
class BankCustomerReport(models.AbstractModel):
_name = 'report.module_name.template_name
def get(self):
self.env.cr.execute(""" you query """+ datas['date_from'],datas['date_to'] ))
line_list = [i for i in self.env.cr.dictfetchall()]
finallist = []
import datetime
for fin in line_list:
#sale_date = datetime.datetime.strptime(fin['date'], '%Y-%m-%d').strftime('%d-%m-%y')
finallist.append({
'date': fin['date'],
'here gat you requirened field from query'
})
finally pass thislist to report template
return finallist
#api.model
def render_html(self, docids, data=None):
Report = self.env['report']
sale_report = Report._get_report_from_name('module_name.report_template_name')
context = dict(self._context or {})
active_ids = context.get('active_ids', [])
register = self.env['bank.customer'].browse(active_ids)
docargs = {
'doc_ids': self.ids,
'doc_model': sale_report.model,
'docs': register,
'details':self.get_det,
}
return Report.render('module_name.report_template_name', docargs)

Odoo: Two selection fields, second selection depends on the first selected value

I have a model with two selection fields. In the first selection field the user chooses a project, and in second the user chooses a tranche, depends on the selected first field. (for one project, we have many tranche)
I use this declaration to my function:
#api.multi
#api.onchange('project')
def _get_tranche(self):
print res
return res`
If I'll print in console the result of returned value is correct, and I have exactly what I search, but in the view, the second field value does not displays computed values to choose after setting the second field value.
Is there any method to make it work properly?
This is my code:
#api.model
def _get_project(self):
values = {'$top' : 100,
'$filter' : "'name==:1&&parent==null'",
'$params' : '\'["*"]\'' }
response = requests.get('http://localhost:8081/rest/Project/name',
auth=('admin', 'admin'),
params=values)
data = response.json()
res = []
for record in data['__ENTITIES']:
res.append((record['__KEY'], record['name']))
return res
#property
def ret_value(self):
return self.project
#api.multi
#api.onchange('project')
def _get_tranche(self):
if self.ret_value == False:
return []
values = {'$top' : 100,
'$filter' : "'parent.ID==:1'",
'$params' : '\'[' + self.ret_value + ']\'' }
response = requests.get('http://localhost:8081/rest/Project/name',
auth=('admin', 'admin'),
params=values)
data = response.json()
res = []
for record in data['__ENTITIES']:
res.append((record['__KEY'], record['name']))
print res
return res
_columns = {
'name': fields.char("Name", required=True),
'description' : fields.text(),
'project' :fields.selection(selection=_get_project, string="Project"),
'tranche' : fields.selection(selection=_get_tranche, string="Tranche"),
}
NB: a tranche is a project with parent_id (not null) = id of a project, I need do the following: when I select a project X from the first field selection "project", I can select the tranches of this project (project with parent_id=X) from the second field selection "tranche" what I can't understand is the result of print in the console is correct, but in the view the field tranche is empty??!!
Now I am trying this:
_columns = {
'name': fields.char("Name", required=True),
'description' : fields.text(),
'project' :fields.selection(selection=_get_project, string="Project"),
'tranche' : fields.selection(selection=_get_tranche,
string="Tranche", compute='_return_tranche'),
}
#api.depends('project')
def _return_tranche(self):
if self.ret_value == False:
self.tranche = []
return
values = {'$top' : 100,
'$filter' : "'parent.ID==:1'",
'$params' : '\'[' + self.ret_value + ']\'' }
response = requests.get('http://localhost:8081/rest/Project/name',
auth=('admin', 'admin'),
params=values)
data = response.json()
res = []
for record in data['__ENTITIES']:
res.append((str(record['__KEY']),str(record['name'])))
print res
self.tranche = res
return
#api.model
def _get_tranche(self):
values = {'$top' : 100,
'$filter' : "'name==:1&&parent!=null'",
'$params' : '\'["*"]\'' }
response = requests.get('http://localhost:8081/rest/Project/name',
auth=('admin', 'admin'),
params=values)
data = response.json()
res = []
for record in data['__ENTITIES']:
res.append((record['__KEY'], record['name']))
return res
But I get this error
File "/opt/odoo/odoo/openerp/fields.py", line 1529, in convert_to_cache
raise ValueError("Wrong value for %s: %r" % (self, value))
ValueError: Wrong value for crm.lead.tranche: [('6', 'Tranche I'), ('7', 'Tranche II'), ('8', 'Tranche III')]
Help me please...