From fff81122c45eca192f795f396771b215b1832360 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Apr 2018 09:45:50 +0200 Subject: [PATCH] Cleaning Code Part 2 --- .vs/AAWeb/v15/.suo | Bin 53248 -> 55296 bytes DailyFileCursor.js | 148 ------------------------- Files/FileServer.js | 261 -------------------------------------------- Project.njsproj | 2 - index.html | 2 - 5 files changed, 413 deletions(-) delete mode 100644 DailyFileCursor.js delete mode 100644 Files/FileServer.js diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 7c7690f6f3682a4e5b1d0417e9de1a6900bbd064..1e366ff7831d7a65f48d06956230f161c335730b 100644 GIT binary patch delta 2571 zcma)7drVVj6u;l?EwoTx<&6l1BBFv)tVpre77C(HsX~-Zd@S%Svaw{cb8c_d&Hb^PoSesZzVn^) zJLmhZXGrB4QH?b4;X}cXy7KOR#Y#DjvlqZVejmFDQ+yX&1$$NdgR0Ry77Kr>Qfe2X zID?;nJWP?J6g~@i0#b~kTagdYGgXC27WeQi^XDB23iWGYp$IX|^T!n_!NG~W0 za}-X_a}~J)O4LU6X4H~kw|aq4j}kO!cZz&NxS>VAhk(sRn}>j11>-6c`yRo)re#5B zr6>?pnWbKf!sjp@Z0t-&i4Guq)kuUdW%w+YX5qpwhpyjNRRt>Z1#ni8D!{V`gdl; z-a*@4vg1kjkv||=I;g!(9+8Rvxs0wDX1^HjW;dWMypvsrsqk_QB^zh}y9R9$b zIPBRl8Bqyk;o0mv+5cPFpE^RwQ^VLd&=z$olCmJ8CJ@+AtxwjG!GH>NK4Rjy@(DS=O6V6w_3P$%h7$^GIvUP@1R%-9l0OE78(kqX6AeGi2|$uF)=3{(&ubY z-$vtrG;Iv##cHRa`n{aNjD+aDL4j(cC1{{FCAa=kLb zpvD|6Md$s@yve)@cY*5d<-t|gLns2A9*Kpf{t(#Wio|qqnz@&_V(4s`2YDM4z+Ukd z{Lnj})d5Rc4Yms@uq7p4-0IYj;~Lse9dU0hhj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{m9%MBzAl8L{n8oPl6PuI);ty;T*gce``CTg=~OZqtTwF}HZ9U-asLl-na zU1pK=?kJ3wi~b5Ls6wA`i5W<7q&5oGWueh4Pwu$FVDybLsU3fjxp&rVu-OtNN98|Y zUJH+z<l~U`pBvAi;YAA#C z@d8|mTk74+O9>X)Qa2vvZRREOG9$~yxB@j6+~#_v{t2_)K+2|i{Yj$F@Ze2MHDsg5 z_S8Gy!=xg?K*C(1I>B9}! z%mo`-Pk6Uzy)Is6+ol*?$gc$3kPXDbOqK;rhhoF;Y&&f%EC1(fq4MreHIM$-2PtB0 z3>_peY^os~25Zm8h_$Y!H=P|0d((DjO9w4r(_srFdqTra&wS3@Z5@S}K1J^jmuiHW zy4i1yZ~HCAh(wKzuru~YPJ=Vx~N!$7y=9kPWAAXx_r@VzfG zka~0Bo+lE9du^x(-@XwB@0?uAW_(hs;e_dqHV{t@%NM#U8Mw|j$I`6`40_9nd*L8M zO~KyY3e27?kBMd$S)E^)Q&3e@l~ZIb7U*f@psByqxOM$Cx_!9HIkjL;@Yd~HoL#xi z?$(y9WhD;yYDtou)N-G(VwoNJi-k4f(^$eexOH3y=ai?~7!Q$03gyp_zRuvSt0pjc zH%o3?@P1T0kr%`fUu;NWuwoz*&h%#nAAQOmkp{=y3Gl&S7qp!Y)zOm^BM%I@nEa4`NfLUq))Z*jI)wY9yih!jlyS?rKiCMmGiI`atUYKHR*t!m9dxv9X=hhBsNCa!AdETrUD4MR<3-YfT zs8Ncc7g{Oi*-?eT4DS&w^;$N0|7H-`Tm%C*(qY6?7PumG$mx2$;=33Zf>ivj{SS>8 BDa`-? diff --git a/DailyFileCursor.js b/DailyFileCursor.js deleted file mode 100644 index ee16add4c..000000000 --- a/DailyFileCursor.js +++ /dev/null @@ -1,148 +0,0 @@ - -function newDailyFilesCursor() { - - const CURSOR_SIZE = 30; - - let dailyFiles = new Map; - let cursorDate = new Date(INITIAL_DATE); - - let dailyFilesCursor = { - setDatetime: setDatetime, - dailyFiles: undefined, - initialize: initialize - } - - dailyFilesCursor.dailyFiles = dailyFiles; - - let marketId; - let exchangeId; - - let server = newFileServer(); - - return dailyFilesCursor; - - function initialize(exchange, market, callBackFunction) { - - marketId = market; - exchangeId = exchange; - - server.initialize(); - - getFiles(callBackFunction); - - } - - function setDatetime(datetime) { - - if (datetime === undefined) { return; } - - cursorDate = datetime; - - getFiles(); - - collectGarbage(); - } - - function getFiles(callBackFunction) { - - let i = 0; - let j = 0; - - let dateString; - - getNextFile(); - - function getNextFile() { - - let targetDate = new Date(cursorDate); - targetDate.setDate(targetDate.getDate() + j); - - if (j === 0) { j++; } - else { - if (j < 0) { - j = -j; - j++; - } - else { - j = -j; - } - } - - dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2); - - let currentDay = Math.trunc((new Date()).valueOf() / (24 * 60 * 60 * 1000)); - let targetDay = Math.trunc(targetDate.valueOf() / (24 * 60 * 60 * 1000)); - - if (targetDay > currentDay) { - - controlLoop(); - - } else { - - if (dailyFilesCursor.dailyFiles.get(dateString) === undefined) { - - server.getDailyFile(exchangeId, marketId, targetDate, newDailyFilesReady) - - } else { - - controlLoop(); - } - - } - - } - - function newDailyFilesReady(dailyFileReceived) { - - dailyFilesCursor.dailyFiles.set(dateString, dailyFileReceived); - - controlLoop(); - - } - - - function controlLoop() { - - if (j === 3) { // We call the callBack after we have the first few files. - - if (callBackFunction !== undefined) { - - callBackFunction(); - - } - - } - - i++; - - if (i < CURSOR_SIZE) { - - getNextFile(); - - } - - } - } - - function collectGarbage() { - - date = removeTime(cursorDate); - - let minDate = date.valueOf() - CURSOR_SIZE / 2 * 24 * 60 * 60 * 1000; - let maxDate = date.valueOf() + CURSOR_SIZE / 2 * 24 * 60 * 60 * 1000; - - for (let key of dailyFilesCursor.dailyFiles.keys()) { - - let keyDate = new Date(key); - - if (keyDate.valueOf() < minDate || keyDate.valueOf() > maxDate) { - - dailyFilesCursor.dailyFiles.delete(key); - - } - - } - - } - -} \ No newline at end of file diff --git a/Files/FileServer.js b/Files/FileServer.js deleted file mode 100644 index 1e0fd37bc..000000000 --- a/Files/FileServer.js +++ /dev/null @@ -1,261 +0,0 @@ - - -/* This module is about to be replaced by FileClound. */ - -function newFileServer() { - - const EXCHANGE_NAME = "Poloniex"; - - const CANDLES_FOLDER_NAME = "Candles"; - const CANDLES_ONE_MIN = "One-Min"; - - const VOLUMES_FOLDER_NAME = "Volumes"; - const VOLUMES_ONE_MIN = "One-Min"; - - var httpServer; // This is the object that allows as to make calls to the fileServer. - - var fileServer = { - getMarkets: getMarkets, - getMarketFilesCandles: getMarketFilesCandles, - getMarketIndexVolumes: getMarketIndexVolumes, - getDailyFile: getDailyFile, - initialize: initialize - }; - - const account = 'aadata'; - const sas = '?sv=2017-04-17&ss=f&srt=sco&sp=r&se=2018-12-01T00:09:44Z&st=2017-12-01T13:09:44Z&spr=https,http&sig=J60UlQuUqh9Hd1Pm0PqIF6yari3D3TkGEz1fSNQJWks%3D'; - const fileUri = 'https://' + account + '.file.core.windows.net'; - - let fileService; - - let charlyFileService; - let carolFileService; - let bruceFileService; - let oliviaFileService; - - const genericBot = { - account: 'aadata', - sas: '?sv=2017-04-17&ss=f&srt=sco&sp=r&se=2018-12-01T00:09:44Z&st=2017-12-01T13:09:44Z&spr=https,http&sig=J60UlQuUqh9Hd1Pm0PqIF6yari3D3TkGEz1fSNQJWks%3D', - fileUri: 'https://' + 'aadata' + '.file.core.windows.net' - }; - - const charlyBot = { - sas: '?sv=2017-04-17&ss=f&srt=sco&sp=rc&se=2018-12-31T02:33:36Z&st=2018-02-01T18:33:36Z&spr=https&sig=xFTcopdKq0f60wl2iuukbtIpcLwxZVKzlw5BzpJfo5g%3D', - fileUri: 'https://' + 'aacharly' + '.file.core.windows.net' - }; - - const carolBot = { - sas: '?sv=2017-04-17&ss=f&srt=sco&sp=r&se=2018-12-01T00:09:44Z&st=2017-12-01T13:09:44Z&spr=https,http&sig=J60UlQuUqh9Hd1Pm0PqIF6yari3D3TkGEz1fSNQJWks%3D', - fileUri: 'https://' + 'aadata' + '.file.core.windows.net' - }; - - const bruceBot = { - sas: '?sv=2017-04-17&ss=f&srt=sco&sp=r&se=2018-12-31T02:32:04Z&st=2018-02-01T18:32:04Z&spr=https&sig=SbZI6bvAE1MBxna2NOvfgMroPFZNjAyaHUsAPvh11hg%3D', - fileUri: 'https://' + 'aabruce' + '.file.core.windows.net' - }; - - const oliviaBot = { - sas: '?sv=2017-04-17&ss=f&srt=sco&sp=rl&se=2018-12-31T02:34:32Z&st=2018-02-01T18:34:32Z&spr=https,http&sig=24UJjGDVpPrHjhBoZtt3iKj4sxgenfSV4VTJD2v0q1U%3D', - fileUri: 'https://' + 'aaolivia' + '.file.core.windows.net' - }; - - return fileServer; - - function initialize() { - - httpServer = new XMLHttpRequest(); - - fileService = AzureStorage.createFileServiceWithSas(fileUri, sas).withFilter(new AzureStorage.ExponentialRetryPolicyFilter()); - - charlyFileService = AzureStorage.createFileServiceWithSas(charlyBot.fileUri, charlyBot.sas).withFilter(new AzureStorage.ExponentialRetryPolicyFilter()); - carolFileService = AzureStorage.createFileServiceWithSas(carolBot.fileUri, carolBot.sas).withFilter(new AzureStorage.ExponentialRetryPolicyFilter()); - bruceFileService = AzureStorage.createFileServiceWithSas(bruceBot.fileUri, bruceBot.sas).withFilter(new AzureStorage.ExponentialRetryPolicyFilter()); - oliviaFileService = AzureStorage.createFileServiceWithSas(oliviaBot.fileUri, oliviaBot.sas).withFilter(new AzureStorage.ExponentialRetryPolicyFilter()); - - } - - function getMarketFilesCandles(exchangeId, marketId, callBackFunction) { - - //let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - - let fileName = '' + 'USDT' + '_' + 'BTC' + '.json'; - let filePath = EXCHANGE_NAME + "/Output/" + CANDLES_FOLDER_NAME + "/Multi-Period-Market/24-hs"; - - oliviaFileService.getFileToText('data', filePath, fileName, undefined, onFileReceived); - - function onFileReceived(err, text, response) { - - let data; - - if (err) { - - data = JSON.parse("[]"); - - } else { - - try { - - data = JSON.parse(text); - - } catch (err) { - - data = JSON.parse("[]"); - - } - } - - callBackFunction(data); - - } - } - - function getMarketIndexVolumes(exchangeId, marketId, callBackFunction) { - - //let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - - let fileName = '' + 'USDT' + '_' + 'BTC' + '.json'; - let filePath = EXCHANGE_NAME + "/Output/" + VOLUMES_FOLDER_NAME + "/Multi-Period-Market/24-hs"; - - oliviaFileService.getFileToText('data', filePath, fileName, undefined, onFileReceived); - - function onFileReceived(err, text, response) { - - let data; - - if (err) { - - data = JSON.parse("[]"); - - } else { - - try { - - data = JSON.parse(text); - - } catch (err) { - - data = JSON.parse("[]"); - - } - } - - callBackFunction(data); - - } - } - - - function getDailyFile(exchangeId, marketId, date, callBackFunction) { - - let fileName = '' + 'USDT' + '_' + 'BTC' + '.json'; - - let dateForPath = date.getUTCFullYear() + '/' + pad(date.getUTCMonth() + 1, 2) + '/' + pad(date.getUTCDate(), 2); - - let filePath = EXCHANGE_NAME + "/Output/" + CANDLES_FOLDER_NAME + '/' + CANDLES_ONE_MIN + '/' + dateForPath; - - bruceFileService.getFileToText('data', filePath, fileName, undefined, onFileReceived); - - function onFileReceived(err, text, response) { - - let data; - - if (err) { - - data = JSON.parse("[]"); - - } else { - - try { - - data = JSON.parse(text); - - } catch (err) { - - data = JSON.parse("[]"); - - } - } - - callBackFunction(data); - - } - - } - - - - - function getMarkets(exchangeId, callBackFunction) { - - let fileName = "Markets_" + exchangeId + "_USDT_BTC" + ".json"; - - fileService.getFileToText('data', 'other-files', fileName, undefined, onFileReceived); - - function onFileReceived(err, text, response) { - - if (err) { - - let data = JSON.parse("[]"); - callBackFunction(data); - - } else { - - var fileString = text; - let cleanString = fileString; - - /* Dont know why but sometimes files comes with a first characater that is not supposed to be there and you can not see it at the file opened with notepad */ - - if (fileString[0] !== "[") { - - cleanString = ''; - - for (let i = 1; i < fileString.length; i++) { - cleanString = cleanString + fileString[i]; - } - } - - let data = JSON.parse(cleanString); - callBackFunction(data); - - } - } - } - - - - - - function checkResponse(callBackFunction) { - - if (httpServer.status === 404) { - - let data = JSON.parse("[]"); - - callBackFunction(data); - - } - - if (httpServer.readyState === 4 && httpServer.status === 200) { - - let data; - - try { - - data = JSON.parse(httpServer.responseText); - - } catch (err) { - - data = JSON.parse("[]"); - - } - - callBackFunction(data); - - } - } - -} - - - - diff --git a/Project.njsproj b/Project.njsproj index f5667362e..192d15b10 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -72,7 +72,6 @@ - Code @@ -98,7 +97,6 @@ - Code diff --git a/index.html b/index.html index 28578b5a5..863c3afee 100644 --- a/index.html +++ b/index.html @@ -43,7 +43,6 @@ - @@ -66,7 +65,6 @@ -