Best JavaScript code snippet using ts-auto-mock
talib_indicators.py
Source:talib_indicators.py
1# coding:utf-82#3# The MIT License (MIT)4#5# Copyright (c) 2016-2021 yutiansut/QUANTAXIS6#7# Permission is hereby granted, free of charge, to any person obtaining a copy8# of this software and associated documentation files (the "Software"), to deal9# in the Software without restriction, including without limitation the rights10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell11# copies of the Software, and to permit persons to whom the Software is12# furnished to do so, subject to the following conditions:13#14# The above copyright notice and this permission notice shall be included in all15# copies or substantial portions of the Software.16#17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE23# SOFTWARE.24import pandas as pd25try:26 import talib27except:28 pass29 #print('PLEASE install TALIB to call these methods')30def AD(DataFrame):31 res = talib.AD(DataFrame.high.values, DataFrame.low.values,32 DataFrame.close.values, DataFrame.volume.values)33 return pd.DataFrame({'AD': res}, index=DataFrame.index)34def ADOSC(DataFrame, N1=3, N2=10):35 res = talib.ADOSC(DataFrame.high.values, DataFrame.low.values,36 DataFrame.close.values, DataFrame.volume.values, N1, N2)37 return pd.DataFrame({'ADOSC': res}, index=DataFrame.index)38def ADX(DataFrame, N=14):39 res = talib.ADX(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values, N)40 return pd.DataFrame({'ADX': res}, index=DataFrame.index)41def ADXR(DataFrame, N=14):42 res = talib.ADXR(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values, N)43 return pd.DataFrame({'ADXR': res}, index=DataFrame.index)44def AROON(DataFrame, N=14):45 """é¿éææ 46 47 Arguments:48 DataFrame {[type]} -- [description]49 50 Keyword Arguments:51 N {int} -- [description] (default: {14})52 53 Returns:54 [type] -- [description]55 """56 ar_up, ar_down = talib.AROON(DataFrame.high.values, DataFrame.low.values, N)57 return pd.DataFrame({'AROON_UP': ar_up,'AROON_DOWN': ar_down}, index=DataFrame.index)58def AROONOSC(DataFrame, N=14):59 res = talib.AROONOSC(DataFrame.high.values, DataFrame.low.values, N)60 return pd.DataFrame({'AROONOSC': res}, index=DataFrame.index)61def ATR(DataFrame, N=14):62 res = talib.ATR(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values, N)63 return pd.DataFrame({'ATR': res}, index=DataFrame.index)64def AVGPRICE(DataFrame):65 res = talib.AVGPRICE(DataFrame.open.values, DataFrame.high.values,66 DataFrame.low.values, DataFrame.close.values)67 return pd.DataFrame({'AVGPRICE': res}, index=DataFrame.index)68def BOP(DataFrame):69 res = talib.BOP(DataFrame.open.values, DataFrame.high.values,70 DataFrame.low.values, DataFrame.close.values)71 return pd.DataFrame({'BOP': res}, index=DataFrame.index)72def CCI(DataFrame, N=14):73 res = talib.CCI(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values, N)74 return pd.DataFrame({'CCI': res}, index=DataFrame.index)75def CDL2CROWS(DataFrame):76 res = talib.CDL2CROWS(DataFrame.open.values, DataFrame.high.values,77 DataFrame.low.values, DataFrame.close.values)78 return pd.DataFrame({'CDL2CROWS': res}, index=DataFrame.index)79def CDL3BLACKCROWS(DataFrame):80 res = talib.CDL3BLACKCROWS(81 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)82 return pd.DataFrame({'CDL3BLACKCROWS': res}, index=DataFrame.index)83def CDL3INSIDE(DataFrame):84 res = talib.CDL3INSIDE(85 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)86 return pd.DataFrame({'CDL3INSIDE': res}, index=DataFrame.index)87def CDL3LINESTRIKE(DataFrame):88 res = talib.CDL3LINESTRIKE(89 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)90 return pd.DataFrame({'CDL3LINESTRIKE': res}, index=DataFrame.index)91def CDL3OUTSIDE(DataFrame):92 res = talib.CDL3OUTSIDE(93 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)94 return pd.DataFrame({'CDL3OUTSIDE': res}, index=DataFrame.index)95def CDL3STARSINSOUTH(DataFrame):96 res = talib.CDL3STARSINSOUTH(97 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)98 return pd.DataFrame({'CDL3STARSINSOUTH': res}, index=DataFrame.index)99def CDL3WHITESOLDIERS(DataFrame):100 res = talib.CDL3WHITESOLDIERS(101 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)102 return pd.DataFrame({'CDL3WHITESOLDIERS': res}, index=DataFrame.index)103def CDLABANDONEDBABY(DataFrame):104 res = talib.CDLABANDONEDBABY(105 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)106 return pd.DataFrame({'CDLABANDONEDBABY': res}, index=DataFrame.index)107def CDLADVANCEBLOCK(DataFrame):108 res = talib.CDLADVANCEBLOCK(109 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)110 return pd.DataFrame({'CDLADVANCEBLOCK': res}, index=DataFrame.index)111def CDLBELTHOLD(DataFrame):112 res = talib.CDLBELTHOLD(113 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)114 return pd.DataFrame({'CDLBELTHOLD': res}, index=DataFrame.index)115def CDLBREAKAWAY(DataFrame):116 res = talib.CDLBREAKAWAY(117 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)118 return pd.DataFrame({'CDLBREAKAWAY': res}, index=DataFrame.index)119def CDLCLOSINGMARUBOZU(DataFrame):120 """121 Closing Marubozu (Pattern Recognition)122 Arguments:123 DataFrame {[type]} -- [description]124 """125 res = talib.CDLCLOSINGMARUBOZU(126 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)127 return pd.DataFrame({'CDLCLOSINGMARUBOZU': res}, index=DataFrame.index)128def CDLCONCEALBABYSWALL(DataFrame):129 res = talib.CDLCONCEALBABYSWALL(130 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)131 return pd.DataFrame({'CDLCONCEALBABYSWALL': res}, index=DataFrame.index)132def CDLCOUNTERATTACK(DataFrame):133 res = talib.CDLCOUNTERATTACK(134 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)135 return pd.DataFrame({'CDLCOUNTERATTACK': res}, index=DataFrame.index)136def CDLDARKCLOUDCOVER(DataFrame):137 res = talib.CDLDARKCLOUDCOVER(138 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)139 return pd.DataFrame({'CDLDARKCLOUDCOVER': res}, index=DataFrame.index)140def CDLDOJI(DataFrame):141 res = talib.CDLDOJI(DataFrame.open.values, DataFrame.high.values,142 DataFrame.low.values, DataFrame.close.values)143 return pd.DataFrame({'CDLDOJI': res}, index=DataFrame.index)144def CDLDOJISTAR(DataFrame):145 res = talib.CDLDOJISTAR(146 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)147 return pd.DataFrame({'CDLDOJISTAR': res}, index=DataFrame.index)148def CDLDRAGONFLYDOJI(DataFrame):149 res = talib.CDLDRAGONFLYDOJI(150 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)151 return pd.DataFrame({'CDLDRAGONFLYDOJI': res}, index=DataFrame.index)152def CDLENGULFING(DataFrame):153 res = talib.CDLENGULFING(154 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)155 return pd.DataFrame({'CDLENGULFING': res}, index=DataFrame.index)156def CDLEVENINGDOJISTAR(DataFrame):157 res = talib.CDLEVENINGDOJISTAR(158 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)159 return pd.DataFrame({'CDLEVENINGDOJISTAR': res}, index=DataFrame.index)160def CDLEVENINGSTAR(DataFrame):161 res = talib.CDLEVENINGSTAR(162 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)163 return pd.DataFrame({'CDLEVENINGSTAR': res}, index=DataFrame.index)164def CDLGAPSIDESIDEWHITE(DataFrame):165 res = talib.CDLGAPSIDESIDEWHITE(166 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)167 return pd.DataFrame({'CDLGAPSIDESIDEWHITE': res}, index=DataFrame.index)168def CDLGRAVESTONEDOJI(DataFrame):169 res = talib.CDLGRAVESTONEDOJI(170 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)171 return pd.DataFrame({'CDLGRAVESTONEDOJI': res}, index=DataFrame.index)172def CDLHAMMER(DataFrame):173 res = talib.CDLHAMMER(DataFrame.open.values, DataFrame.high.values,174 DataFrame.low.values, DataFrame.close.values)175 return pd.DataFrame({'CDLHAMMER': res}, index=DataFrame.index)176def CDLHANGINGMAN(DataFrame):177 res = talib.CDLHANGINGMAN(178 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)179 return pd.DataFrame({'CDLHANGINGMAN': res}, index=DataFrame.index)180def CDLHARAMI(DataFrame):181 res = talib.CDLHARAMI(DataFrame.open.values, DataFrame.high.values,182 DataFrame.low.values, DataFrame.close.values)183 return pd.DataFrame({'CDLHARAMI': res}, index=DataFrame.index)184def CDLHARAMICROSS(DataFrame):185 res = talib.CDLHARAMICROSS(186 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)187 return pd.DataFrame({'CDLHARAMICROSS': res}, index=DataFrame.index)188def CDLHIGHWAVE(DataFrame):189 res = talib.CDLHIGHWAVE(190 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)191 return pd.DataFrame({'CDLHIGHWAVE': res}, index=DataFrame.index)192def CDLHIKKAKE(DataFrame):193 res = talib.CDLHIKKAKE(DataFrame.open.values, DataFrame.high.values,194 DataFrame.low.values, DataFrame.close.values)195 return pd.DataFrame({'CDLHIKKAKE': res}, index=DataFrame.index)196def CDLHIKKAKEMOD(DataFrame):197 res = talib.CDLHIKKAKEMOD(198 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)199 return pd.DataFrame({'CDLHIKKAKEMOD': res}, index=DataFrame.index)200def CDLHOMINGPIGEON(DataFrame):201 res = talib.CDLHOMINGPIGEON(202 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)203 return pd.DataFrame({'CDLHOMINGPIGEON': res}, index=DataFrame.index)204def CDLIDENTICAL3CROWS(DataFrame):205 res = talib.CDLIDENTICAL3CROWS(206 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)207 return pd.DataFrame({'CDLIDENTICAL3CROWS': res}, index=DataFrame.index)208def CDLINNECK(DataFrame):209 res = talib.CDLINNECK(DataFrame.open.values, DataFrame.high.values,210 DataFrame.low.values, DataFrame.close.values)211 return pd.DataFrame({'CDLINNECK': res}, index=DataFrame.index)212def CDLINVERTEDHAMMER(DataFrame):213 res = talib.CDLINVERTEDHAMMER(214 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)215 return pd.DataFrame({'CDLINVERTEDHAMMER': res}, index=DataFrame.index)216def CDLKICKING(DataFrame):217 res = talib.CDLKICKING(DataFrame.open.values, DataFrame.high.values,218 DataFrame.low.values, DataFrame.close.values)219 return pd.DataFrame({'CDLKICKING': res}, index=DataFrame.index)220def CDLKICKINGBYLENGTH(DataFrame):221 res = talib.CDLKICKINGBYLENGTH(222 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)223 return pd.DataFrame({'CDLKICKINGBYLENGTH': res}, index=DataFrame.index)224def CDLLADDERBOTTOM(DataFrame):225 res = talib.CDLLADDERBOTTOM(226 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)227 return pd.DataFrame({'CDLLADDERBOTTOM': res}, index=DataFrame.index)228def CDLLONGLEGGEDDOJI(DataFrame):229 res = talib.CDLLONGLEGGEDDOJI(230 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)231 return pd.DataFrame({'CDLLONGLEGGEDDOJI': res}, index=DataFrame.index)232def CDLLONGLINE(DataFrame):233 res = talib.CDLLONGLINE(234 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)235 return pd.DataFrame({'CDLLONGLINE': res}, index=DataFrame.index)236def CDLMARUBOZU(DataFrame):237 res = talib.CDLMARUBOZU(238 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)239 return pd.DataFrame({'CDLMARUBOZU': res}, index=DataFrame.index)240def CDLMATCHINGLOW(DataFrame):241 res = talib.CDLMATCHINGLOW(242 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)243 return pd.DataFrame({'CDLMATCHINGLOW': res}, index=DataFrame.index)244def CDLMATHOLD(DataFrame):245 res = talib.CDLMATHOLD(DataFrame.open.values, DataFrame.high.values,246 DataFrame.low.values, DataFrame.close.values)247 return pd.DataFrame({'CDLMATHOLD': res}, index=DataFrame.index)248def CDLMORNINGDOJISTAR(DataFrame):249 res = talib.CDLMORNINGDOJISTAR(250 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)251 return pd.DataFrame({'CDLMORNINGDOJISTAR': res}, index=DataFrame.index)252def CDLMORNINGSTAR(DataFrame):253 res = talib.CDLMORNINGSTAR(254 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)255 return pd.DataFrame({'CDLMORNINGSTAR': res}, index=DataFrame.index)256def CDLONNECK(DataFrame):257 res = talib.CDLONNECK(DataFrame.open.values, DataFrame.high.values,258 DataFrame.low.values, DataFrame.close.values)259 return pd.DataFrame({'CDLONNECK': res}, index=DataFrame.index)260def CDLPIERCING(DataFrame):261 res = talib.CDLPIERCING(262 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)263 return pd.DataFrame({'CDLPIERCING': res}, index=DataFrame.index)264def CDLRICKSHAWMAN(DataFrame):265 res = talib.CDLRICKSHAWMAN(266 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)267 return pd.DataFrame({'CDLRICKSHAWMAN': res}, index=DataFrame.index)268def CDLRISEFALL3METHODS(DataFrame):269 res = talib.CDLRISEFALL3METHODS(270 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)271 return pd.DataFrame({'CDLRISEFALL3METHODS': res}, index=DataFrame.index)272def CDLSEPARATINGLINES(DataFrame):273 res = talib.CDLSEPARATINGLINES(274 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)275 return pd.DataFrame({'CDLSEPARATINGLINES': res}, index=DataFrame.index)276def CDLSHOOTINGSTAR(DataFrame):277 res = talib.CDLSHOOTINGSTAR(278 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)279 return pd.DataFrame({'CDLSHOOTINGSTAR': res}, index=DataFrame.index)280def CDLSHORTLINE(DataFrame):281 res = talib.CDLSHORTLINE(282 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)283 return pd.DataFrame({'CDLSHORTLINE': res}, index=DataFrame.index)284def CDLSPINNINGTOP(DataFrame):285 res = talib.CDLSPINNINGTOP(286 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)287 return pd.DataFrame({'CDLSPINNINGTOP': res}, index=DataFrame.index)288def CDLSTALLEDPATTERN(DataFrame):289 res = talib.CDLSTALLEDPATTERN(290 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)291 return pd.DataFrame({'CDLSTALLEDPATTERN': res}, index=DataFrame.index)292def CDLSTICKSANDWICH(DataFrame):293 res = talib.CDLSTICKSANDWICH(294 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)295 return pd.DataFrame({'CDLSTICKSANDWICH': res}, index=DataFrame.index)296def CDLTAKURI(DataFrame):297 res = talib.CDLTAKURI(DataFrame.open.values, DataFrame.high.values,298 DataFrame.low.values, DataFrame.close.values)299 return pd.DataFrame({'CDLTAKURI': res}, index=DataFrame.index)300def CDLTASUKIGAP(DataFrame):301 res = talib.CDLTASUKIGAP(302 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)303 return pd.DataFrame({'CDLTASUKIGAP': res}, index=DataFrame.index)304def CDLTHRUSTING(DataFrame):305 res = talib.CDLTHRUSTING(306 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)307 return pd.DataFrame({'CDLTHRUSTING': res}, index=DataFrame.index)308def CDLTRISTAR(DataFrame):309 res = talib.CDLTRISTAR(DataFrame.open.values, DataFrame.high.values,310 DataFrame.low.values, DataFrame.close.values)311 return pd.DataFrame({'CDLTRISTAR': res}, index=DataFrame.index)312def CDLUNIQUE3RIVER(DataFrame):313 res = talib.CDLUNIQUE3RIVER(314 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)315 return pd.DataFrame({'CDLUNIQUE3RIVER': res}, index=DataFrame.index)316def CDLUPSIDEGAP2CROWS(DataFrame):317 res = talib.CDLUPSIDEGAP2CROWS(318 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)319 return pd.DataFrame({'CDLUPSIDEGAP2CROWS': res}, index=DataFrame.index)320def CDLXSIDEGAP3METHODS(DataFrame):321 res = talib.CDLXSIDEGAP3METHODS(322 DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values)323 return pd.DataFrame({'CDLXSIDEGAP3METHODS': res}, index=DataFrame.index)324def DX(DataFrame, N=14):325 res = talib.DX(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values, N)326 return pd.DataFrame({'DX': res}, index=DataFrame.index)327# SAR - Parabolic SAR328def SAR(DataFrame, acceleration=0, maximum=0):329 res = talib.SAR(DataFrame.high.values, DataFrame.low.values, acceleration, maximum)330 return pd.DataFrame({'SAR': res}, index=DataFrame.index)331def SAREXT(DataFrame, startvalue=0, offsetonreverse=0, accelerationinitlong=0,332 accelerationlong=0, accelerationmaxlong=0, accelerationinitshort=0, accelerationshort=0, accelerationmaxshort=0):333 res = talib.SAREXT(DataFrame.high.values, DataFrame.low.values,334 startvalue, offsetonreverse, accelerationinitlong, accelerationlong, accelerationmaxlong,335 accelerationinitshort, accelerationshort, accelerationmaxshort)336 return pd.DataFrame({'SAREXT': res}, index=DataFrame.index)337def STOCH(DataFrame, fastk_period=5, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0):338 slowk, slowd = talib.STOCH(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values,339 fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype)340 return pd.DataFrame({'STOCH_SLOWK': slowk, 'STOCH_SLOWD': slowd}, index=DataFrame.index)341def STOCHF(DataFrame, fastk_period=5, fastd_period=3, fastd_matype=0):342 fastk, fastd = talib.STOCHF(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values,343 fastk_period, fastd_period, fastd_matype)...
qgis2web_expressions.js
Source:qgis2web_expressions.js
1// Aggregates2// Color3// Conditionals4// Conversions5// Custom6// Date and Time7// Fields and Values8// Fuzzy Matching9// General10// Geometry11function fnc_azimuth(values, context) {12 return false;13};14function fnc_project(values, context) {15 return false;16};17// Math18function fnc_abs(values, context) {19 return Math.abs(values[0]);20};21function fnc_degrees(values, context) {22 return values[0] * (180/Math.PI);23};24function fnc_radians(values, context) {25 return values[0] * (Math.PI/180);26};27function fnc_sqrt(values, context) {28 return Math.sqrt(values[0]);29};30function fnc_cos(values, context) {31 return Math.cos(values[0]);32};33function fnc_sin(values, context) {34 return Math.sin(values[0]);35};36function fnc_tan(values, context) {37 return Math.tan(values[0]);38};39function fnc_asin(values, context) {40 return Math.asin(values[0]);41};42function fnc_acos(values, context) {43 return Math.acos(values[0]);44};45function fnc_atan(values, context) {46 return Math.atan(values[0]);47};48function fnc_atan2(values, context) {49 return Math.atan2(values[0]);50};51function fnc_exp(values, context) {52 return Math.exp(values[0]);53};54function fnc_ln(values, context) {55 return Math.log(values[0]);56};57function fnc_log10(values, context) {58 return Math.LN10(values[0]);59};60function fnc_log(values, context) {61 return Math.log(values[0]) / Math.log(values[1]);62};63function fnc_round(values, context) {64 return Math.round(values[0]);65};66function fnc_rand(values, context) {67 return Math.floor(Math.random()*(values[1]-values[0]+1)+values[0]);68};69function fnc_randf(values, context) {70 return Math.random()*(values[1]-values[0]+1)+values[0];71};72function fnc_max(values, context) {73 return Math.max.apply(this, values);74};75function fnc_min(values, context) {76 return Math.min.apply(this, values);77};78function fnc_clamp(values, context) {79 return Math.min(Math.max(values[0],values[1]),values[2]);80};81// Operators82// Record83// String84// TimeManager85// Variables86function fnc_scale_linear(values, context) {87 return false;88};89function fnc_scale_exp(values, context) {90 return false;91};92function fnc_floor(values, context) {93 return Math.floor(values[0]);94};95function fnc_ceil(values, context) {96 return Math.ceil(values[0]);97};98function fnc_pi(values, context) {99 return Math.PI;100};101function fnc_to_int(values, context) {102 var intVal = parseInt(values[0],10);103 if ( isNaN(intVal) ) { return false };104 return intVal;105};106function fnc_to_real(values, context) {107 var realVal = parseFloat(values[0]);108 if ( isNaN(realVal) ) { return false };109 return realVal;110};111function fnc_to_string(values, context) {112 return String(values[0]);113};114function fnc_to_datetime(values, context) {115 return false;116};117function fnc_to_date(values, context) {118 return false;119};120function fnc_to_time(values, context) {121 return false;122};123function fnc_to_interval(values, context) {124 return false;125};126function fnc_coalesce(values, context) {127 return false;128};129function fnc_if(values, context) {130 return false;131};132function fnc_aggregate(values, context) {133 return false;134};135function fnc_relation_aggregate(values, context) {136 return false;137};138function fnc_count(values, context) {139 return false;140};141function fnc_count_distinct(values, context) {142 return false;143};144function fnc_count_missing(values, context) {145 return false;146};147function fnc_minimum(values, context) {148 return false;149};150function fnc_maximum(values, context) {151 return false;152};153function fnc_sum(values, context) {154 return false;155};156function fnc_mean(values, context) {157 return false;158};159function fnc_median(values, context) {160 return false;161};162function fnc_stdev(values, context) {163 return false;164};165function fnc_range(values, context) {166 return false;167};168function fnc_minority(values, context) {169 return false;170};171function fnc_majority(values, context) {172 return false;173};174function fnc_q1(values, context) {175 return false;176};177function fnc_q3(values, context) {178 return false;179};180function fnc_iqr(values, context) {181 return false;182};183function fnc_min_length(values, context) {184 return false;185};186function fnc_max_length(values, context) {187 return false;188};189function fnc_concatenate(values, context) {190 return false;191};192function fnc_regexp_match(values, context) {193 return false;194};195function fnc_now(values, context) {196 return new Date().toISOString();197};198function fnc_age(values, context) {199 return false;200};201function fnc_year(values, context) {202 return false;203};204function fnc_month(values, context) {205 return false;206};207function fnc_week(values, context) {208 return false;209};210function fnc_day(values, context) {211 return false;212};213function fnc_hour(values, context) {214 return false;215};216function fnc_minute(values, context) {217 return false;218};219function fnc_second(values, context) {220 return false;221};222function fnc_day_of_week(values, context) {223 return false;224};225function fnc_lower(values, context) {226 if ( typeof values[0] != "string" ) { return false; } 227 return values[0].toLowerCase();228};229function fnc_upper(values, context) {230 if ( typeof values[0] != "string" ) { return false; } 231 return values[0].toUpperCase();232};233function fnc_title(values, context) {234 if ( typeof values[0] != "string" ) { return false; }235 return values[0].toLowerCase().split(' ').map(function(word) {236 return (word.charAt(0).toUpperCase() + word.slice(1));237 }).join(' ');238};239function fnc_trim(values, context) {240 if ( typeof values[0] != "string" ) { return false; } 241 return String(values[0]).trim();242};243function fnc_levenshtein(values, context) {244 return false;245};246function fnc_longest_common_substring(values, context) {247 return false;248};249function fnc_hamming_distance(values, context) {250 return false;251};252function fnc_soundex(values, context) {253 return false;254};255function fnc_char(values, context) {256 if ( isNaN(values[0]) || !values[0]) { return null; } return String.fromCodePoint(values[0]);257};258function fnc_wordwrap(values, context) {259 return false;260};261function fnc_length(values, context) {262 return false;263};264function fnc_replace(values, context) {265 return false;266};267function fnc_regexp_replace(values, context) {268 if ( !values[0] ) { return null; } return String(values[0]).replace(RegExp(values[1]),values[2]);269};270function fnc_regexp_substr(values, context) {271 if ( !values[0] ) { return null; }272 return String(values[0]).match(RegExp(values[1]))[0];273};274function fnc_substr(values, context) {275 var length = values[2]276 if ( !values[0] || isNaN(values[1])) { return false; }277 return String(values[0]).substr(values[1], length);278};279function fnc_concat(values, context) {280 return values.join(''); 281};282function fnc_strpos(values, context) {283 if (!values[0] || !values[1]) {return null}284 return String(values[0]).indexOf(String(values[1]))+1;285};286function fnc_left(values, context) {287 return false;288};289function fnc_right(values, context) {290 return false;291};292function fnc_rpad(values, context) {293 return false;294};295function fnc_lpad(values, context) {296 return false;297};298function fnc_format(values, context) {299 return false;300};301function fnc_format_number(values, context) {302 return false;303};304function fnc_format_date(values, context) {305 return false;306};307function fnc_color_rgb(values, context) {308 return false;309};310function fnc_color_rgba(values, context) {311 return false;312};313function fnc_ramp_color(values, context) {314 return false;315};316function fnc_color_hsl(values, context) {317 return false;318};319function fnc_color_hsla(values, context) {320 return false;321};322function fnc_color_hsv(values, context) {323 return false;324};325function fnc_color_hsva(values, context) {326 return false;327};328function fnc_color_cmyk(values, context) {329 return false;330};331function fnc_color_cmyka(values, context) {332 return false;333};334function fnc_color_part(values, context) {335 return false;336};337function fnc_darker(values, context) {338 return false;339};340function fnc_lighter(values, context) {341 return false;342};343function fnc_set_color_part(values, context) {344 return false;345};346function fnc_area(values, context) {347 return false;348};349function fnc_perimeter(values, context) {350 return false;351};352function fnc_x(values, context) {353 return false;354};355function fnc_y(values, context) {356 return false;357};358function fnc_z(values, context) {359 return false;360};361function fnc_m(values, context) {362 return false;363};364function fnc_point_n(values, context) {365 return false;366};367function fnc_start_point(values, context) {368 return false;369};370function fnc_end_point(values, context) {371 return false;372};373function fnc_nodes_to_points(values, context) {374 return false;375};376function fnc_segments_to_lines(values, context) {377 return false;378};379function fnc_make_point(values, context) {380 return false;381};382function fnc_make_point_m(values, context) {383 return false;384};385function fnc_make_line(values, context) {386 return false;387};388function fnc_make_polygon(values, context) {389 return false;390};391function fnc_x_min(values, context) {392 return false;393};394function fnc_x_max(values, context) {395 return false;396};397function fnc_y_min(values, context) {398 return false;399};400function fnc_y_max(values, context) {401 return false;402};403function fnc_geom_from_wkt(values, context) {404 return false;405};406function fnc_geom_from_gml(values, context) {407 return false;408};409function fnc_relate(values, context) {410 return false;411};412function fnc_intersects_bbox(values, context) {413 return false;414};415function fnc_disjoint(values, context) {416 return false;417};418function fnc_intersects(values, context) {419 return false;420};421function fnc_touches(values, context) {422 return false;423};424function fnc_crosses(values, context) {425 return false;426};427function fnc_contains(values, context) {428 return false;429};430function fnc_overlaps(values, context) {431 return false;432};433function fnc_within(values, context) {434 return false;435};436function fnc_translate(values, context) {437 return false;438};439function fnc_buffer(values, context) {440 return false;441};442function fnc_centroid(values, context) {443 return false;444};445function fnc_point_on_surface(values, context) {446 return false;447};448function fnc_reverse(values, context) {449 return false;450};451function fnc_exterior_ring(values, context) {452 return false;453};454function fnc_interior_ring_n(values, context) {455 return false;456};457function fnc_geometry_n(values, context) {458 return false;459};460function fnc_boundary(values, context) {461 return false;462};463function fnc_line_merge(values, context) {464 return false;465};466function fnc_bounds(values, context) {467 return false;468};469function fnc_num_points(values, context) {470 return false;471};472function fnc_num_interior_rings(values, context) {473 return false;474};475function fnc_num_rings(values, context) {476 return false;477};478function fnc_num_geometries(values, context) {479 return false;480};481function fnc_bounds_width(values, context) {482 return false;483};484function fnc_bounds_height(values, context) {485 return false;486};487function fnc_is_closed(values, context) {488 return false;489};490function fnc_convex_hull(values, context) {491 return false;492};493function fnc_difference(values, context) {494 return false;495};496function fnc_distance(values, context) {497 return false;498};499function fnc_intersection(values, context) {500 return false;501};502function fnc_sym_difference(values, context) {503 return false;504};505function fnc_combine(values, context) {506 return false;507};508function fnc_union(values, context) {509 return false;510};511function fnc_geom_to_wkt(values, context) {512 return false;513};514function fnc_geometry(values, context) {515 return false;516};517function fnc_transform(values, context) {518 return false;519};520function fnc_extrude(values, context) {521 return false;522};523function fnc_order_parts(values, context) {524 return false;525};526function fnc_closest_point(values, context) {527 return false;528};529function fnc_shortest_line(values, context) {530 return false;531};532function fnc_line_interpolate_point(values, context) {533 return false;534};535function fnc_line_interpolate_angle(values, context) {536 return false;537};538function fnc_line_locate_point(values, context) {539 return false;540};541function fnc_angle_at_vertex(values, context) {542 return false;543};544function fnc_distance_to_vertex(values, context) {545 return false;546};547function fnc_uuid(values, context) {548 return false;549};550function fnc_get_feature(values, context) {551 return false;552};553function fnc_layer_property(values, context) {554 return false;555};556function fnc_var(values, context) {557 return false;558};559function fnc_eval(values, context) {560 return false;561};562function fnc_attribute(values, context) {563 return false;564};565function fnc__specialcol_(values, context) {566 return false;567};568function fnc_project_color(values, context) {569 return false;...
merge_values_unittest.py
Source:merge_values_unittest.py
1# Copyright 2013 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import os5import unittest6from telemetry import story7from telemetry import page as page_module8from telemetry.value import improvement_direction9from telemetry.value import list_of_scalar_values10from telemetry.value import merge_values11from telemetry.value import scalar12class TestBase(unittest.TestCase):13 def setUp(self):14 story_set = story.StorySet(base_dir=os.path.dirname(__file__))15 story_set.AddStory(16 page_module.Page('http://www.bar.com/', story_set, story_set.base_dir))17 story_set.AddStory(18 page_module.Page('http://www.baz.com/', story_set, story_set.base_dir))19 story_set.AddStory(20 page_module.Page('http://www.foo.com/', story_set, story_set.base_dir))21 self.story_set = story_set22 @property23 def pages(self):24 return self.story_set.stories25class MergeValueTest(TestBase):26 def testDefaultKeyFuncWithTirLabel(self):27 page0 = self.pages[0]28 value = scalar.ScalarValue(29 page0, 'x', 'units', 1,30 improvement_direction=improvement_direction.UP,31 tir_label='foo')32 self.assertEquals(('x', 'foo'), merge_values.DefaultKeyFunc(value))33 def testSamePageMergeBasic(self):34 page0 = self.pages[0]35 page1 = self.pages[1]36 all_values = [scalar.ScalarValue(37 page0, 'x', 'units', 1,38 improvement_direction=improvement_direction.UP),39 scalar.ScalarValue(40 page1, 'x', 'units', 4,41 improvement_direction=improvement_direction.UP),42 scalar.ScalarValue(43 page0, 'x', 'units', 2,44 improvement_direction=improvement_direction.UP),45 scalar.ScalarValue(46 page1, 'x', 'units', 5,47 improvement_direction=improvement_direction.UP)]48 merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)49 # Sort the results so that their order is predictable for the subsequent50 # assertions.51 merged_values.sort(key=lambda x: x.page.url)52 self.assertEquals(2, len(merged_values))53 self.assertEquals((page0, 'x'),54 (merged_values[0].page, merged_values[0].name))55 self.assertEquals([1, 2], merged_values[0].values)56 self.assertEquals((page1, 'x'),57 (merged_values[1].page, merged_values[1].name))58 self.assertEquals([4, 5], merged_values[1].values)59 def testSamePageMergeNonstandardKeyFunc(self):60 page0 = self.pages[0]61 page1 = self.pages[1]62 all_values = [scalar.ScalarValue(63 page0, 'x', 'units', 1,64 improvement_direction=improvement_direction.UP),65 scalar.ScalarValue(66 page1, 'x', 'units', 4,67 improvement_direction=improvement_direction.UP),68 scalar.ScalarValue(69 page0, 'y', 'units', 2,70 improvement_direction=improvement_direction.UP),71 scalar.ScalarValue(72 page1, 'y', 'units', 5,73 improvement_direction=improvement_direction.UP)]74 merged_values = merge_values.MergeLikeValuesFromSamePage(75 all_values, key_func=lambda v: v.page.display_name)76 # Sort the results so that their order is predictable for the subsequent77 # assertions.78 merged_values.sort(key=lambda x: x.page.url)79 self.assertEquals(2, len(merged_values))80 self.assertEquals([1, 2], merged_values[0].values)81 self.assertEquals([4, 5], merged_values[1].values)82 def testSamePageMergeOneValue(self):83 page0 = self.pages[0]84 all_values = [scalar.ScalarValue(85 page0, 'x', 'units', 1,86 improvement_direction=improvement_direction.DOWN)]87 # Sort the results so that their order is predictable for the subsequent88 # assertions.89 merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)90 self.assertEquals(1, len(merged_values))91 self.assertEquals(all_values[0].name, merged_values[0].name)92 self.assertEquals(all_values[0].units, merged_values[0].units)93 def testSamePageMergeWithInteractionRecord(self):94 page0 = self.pages[0]95 all_values = [scalar.ScalarValue(96 page0, 'foo-x', 'units', 1, tir_label='foo',97 improvement_direction=improvement_direction.UP),98 scalar.ScalarValue(99 page0, 'foo-x', 'units', 4, tir_label='foo',100 improvement_direction=improvement_direction.UP)]101 merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)102 self.assertEquals(1, len(merged_values))103 self.assertEquals('foo', merged_values[0].tir_label)104 def testSamePageMergeWithTwoInteractionRecords(self):105 page0 = self.pages[0]106 all_values = [scalar.ScalarValue(page0, 'x', 'units', 1, tir_label='foo'),107 scalar.ScalarValue(page0, 'x', 'units', 4, tir_label='bar')]108 merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)109 self.assertEquals(2, len(merged_values))110 self.assertEquals('foo', merged_values[0].tir_label)111 self.assertEquals('bar', merged_values[1].tir_label)112 def testDifferentPageMergeBasic(self):113 page0 = self.pages[0]114 page1 = self.pages[1]115 all_values = [scalar.ScalarValue(116 page0, 'x', 'units', 1,117 improvement_direction=improvement_direction.UP),118 scalar.ScalarValue(119 page1, 'x', 'units', 2,120 improvement_direction=improvement_direction.UP),121 scalar.ScalarValue(122 page0, 'y', 'units', 10,123 improvement_direction=improvement_direction.UP),124 scalar.ScalarValue(125 page1, 'y', 'units', 20,126 improvement_direction=improvement_direction.UP)]127 merged_values = merge_values.MergeLikeValuesFromDifferentPages(all_values)128 merged_values.sort(key=lambda x: x.name)129 self.assertEquals(2, len(merged_values))130 self.assertEquals((None, 'x'),131 (merged_values[0].page, merged_values[0].name))132 self.assertEquals([1, 2], merged_values[0].values)133 self.assertEquals((None, 'y'),134 (merged_values[1].page, merged_values[1].name))135 self.assertEquals([10, 20], merged_values[1].values)136 def testDifferentPageMergeNonstandardKeyFunc(self):137 page0 = self.pages[0]138 page1 = self.pages[1]139 all_values = [scalar.ScalarValue(140 page0, 'x', 'units', 1,141 improvement_direction=improvement_direction.UP),142 scalar.ScalarValue(143 page1, 'x', 'units', 2,144 improvement_direction=improvement_direction.UP),145 scalar.ScalarValue(146 page0, 'y', 'units', 10,147 improvement_direction=improvement_direction.UP),148 scalar.ScalarValue(149 page1, 'y', 'units', 20,150 improvement_direction=improvement_direction.UP)]151 merged_values = merge_values.MergeLikeValuesFromDifferentPages(152 all_values, key_func=lambda v: True)153 self.assertEquals(1, len(merged_values))154 self.assertEquals([1, 2, 10, 20], merged_values[0].values)155 def testDifferentPageMergeSingleValueStillMerges(self):156 page0 = self.pages[0]157 all_values = [scalar.ScalarValue(158 page0, 'x', 'units', 1,159 improvement_direction=improvement_direction.DOWN)]160 # Sort the results so that their order is predictable for the subsequent161 # assertions.162 merged_values = merge_values.MergeLikeValuesFromDifferentPages(all_values)163 self.assertEquals(1, len(merged_values))164 self.assertEquals((None, 'x'),165 (merged_values[0].page, merged_values[0].name))166 self.assertTrue(167 isinstance(merged_values[0], list_of_scalar_values.ListOfScalarValues))168 self.assertEquals([1], merged_values[0].values)169 def testDifferentPageMergeWithInteractionRecord(self):170 page0 = self.pages[0]171 page1 = self.pages[1]172 v0 = scalar.ScalarValue(page0, 'x', 'units', 1, tir_label='foo')173 v1 = scalar.ScalarValue(page0, 'y', 'units', 30, tir_label='bar')174 v2 = scalar.ScalarValue(page1, 'x', 'units', 2, tir_label='foo')175 v3 = scalar.ScalarValue(page1, 'y', 'units', 40, tir_label='baz')176 all_values = [v0, v1, v2, v3]177 merged_x = list_of_scalar_values.ListOfScalarValues(178 None, 'x', 'units', [1, 2], tir_label='foo')179 merged_y_bar = list_of_scalar_values.ListOfScalarValues(180 None, 'y', 'units', [30], tir_label='bar')181 merged_y_baz = list_of_scalar_values.ListOfScalarValues(182 None, 'y', 'units', [40], tir_label='baz')183 merged_values = merge_values.MergeLikeValuesFromDifferentPages(all_values)184 merged_values.sort(key=lambda x: x.tir_label)...
test_knapsack_with_repetitions.py
Source:test_knapsack_with_repetitions.py
...16 capacity = -117 weights = []18 values = []19 optimal_value(capacity, weights, values)20 def test_with_less_weights_than_values(self):21 with self.assertRaisesRegex(AssertionError, ''):22 capacity = 123 weights = [ 1 ]24 values = [ 2, 3 ]25 optimal_value(capacity, weights, values)26 def test_with_more_weights_than_values(self):27 with self.assertRaisesRegex(AssertionError, ''):28 capacity = 129 weights = [ 1, 2 ]30 values = [ 3 ]31 optimal_value(capacity, weights, values)32 def test_with_preceeding_lower_bound_of_weights(self):33 with self.assertRaisesRegex(AssertionError, ''):34 capacity = 135 weights = [ 1, -1, 2 ]36 values = [ 1, 2, 3 ]37 optimal_value(capacity, weights, values)38 def test_with_preceeding_lower_bound_of_values(self):39 with self.assertRaisesRegex(AssertionError, ''):40 capacity = 141 weights = [ 1, 2, 3 ]42 values = [ 1, -1, 2 ]43 optimal_value(capacity, weights, values)44 def test_with_zero_capacity(self):45 capacity = 046 weights = []47 values = []48 value, items = optimal_value(capacity, weights, values)49 self.assertEqual(0, value)50 self.assertEqual([], items)51 self.assert_items_within_capacity(capacity, weights, values,52 value, items)53 def test_with_non_zero_capacity_and_empty_items(self):54 capacity = 12355 weights = []56 values = []57 value, items = optimal_value(capacity, weights, values)58 self.assertEqual(0, value)59 self.assertEqual([], items)60 self.assert_items_within_capacity(capacity, weights, values,61 value, items)62 def test_with_capacity_as_1_and_weights_as_1(self):63 capacity = 164 weights = [ 1 ]65 values = [ 2 ]66 value, items = optimal_value(capacity, weights, values)67 self.assertEqual(2, value)68 self.assertEqual([ 0 ], items)69 self.assert_items_within_capacity(capacity, weights, values,70 value, items)71 def test_with_capacity_as_1_and_duplicate_weights_and_values(self):72 capacity = 173 weights = [ 1, 1 ]74 values = [ 2, 2 ]75 value, items = optimal_value(capacity, weights, values)76 self.assertEqual(2, value)77 self.assertEqual([ 0 ], items)78 self.assert_items_within_capacity(capacity, weights, values,79 value, items)80 def test_with_capacity_as_1_and_duplicate_weights(self):81 capacity = 182 weights = [ 1, 1 ]83 values = [ 2, 3 ]84 value, items = optimal_value(capacity, weights, values)85 self.assertEqual(3, value)86 self.assertEqual([ 1 ], items)87 self.assert_items_within_capacity(capacity, weights, values,88 value, items)89 def test_with_capacity_as_1_and_duplicate_values(self):90 capacity = 191 weights = [ 1, 2 ]92 values = [ 2, 2 ]93 value, items = optimal_value(capacity, weights, values)94 self.assertEqual(2, value)95 self.assertEqual([ 0 ], items)96 self.assert_items_within_capacity(capacity, weights, values,97 value, items)98 def test_with_capacity_as_1_and_weights_as_2(self):99 capacity = 1100 weights = [ 2 ]101 values = [ 3 ]102 value, items = optimal_value(capacity, weights, values)103 self.assertEqual(0, value)...
VelocityCurve.py
Source:VelocityCurve.py
1#!/usr/bin/env python2# -*- coding: Latin-1 -*-3"""4@file VelocityCurve.py5@author Sascha Krieg6@author Daniel Krajzewicz7@author Michael Behrisch8@date 2008-05-139@version $Id: VelocityCurve.py 18096 2015-03-17 09:50:59Z behrisch $10Shows a velocity time-variation curve for a given Taxi or for the hole day all average values.11SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/12Copyright (C) 2008-2015 DLR (http://www.dlr.de/) and contributors13This file is part of SUMO.14SUMO is free software; you can redistribute it and/or modify15it under the terms of the GNU General Public License as published by16the Free Software Foundation; either version 3 of the License, or17(at your option) any later version.18"""19from pylab import *20from analysis.Taxi import *21import util.Reader as reader22#global Vars23WEE = True # =withoutEmptyEdges decide which analysis file should be used24def main():25 print "start program"26 taxiId = '154_2'27 interval = 90028 plotCurve(interval)29 show()30 print "end"31def plotCurve(interval=10, taxiId=None):32 """plots the velocity time-variation curve for a single taxi or averaged values of the hole day."""33 if taxiId == None:34 values, interval = getAveragedValues(interval)35 legendText = ('reale FCD', 'sim. FCD', 'sim. FC-Rohdaten')36 else:37 values, starttime = getDataForTaxi(taxiId)38 legendText = (39 'reale FCD', 'sim. FCD', 'vtype', 'start: ' + str(starttime))40 textsize = 1641 subplot(211)42 #plot(values[0], values[1], values[0], values[2],'red',values[0], values[3],'grey')43 plot(values[0], values[7]) # rel Error44 # plot(values[0],values[8]) #abs Error45 # plot(values[0], values[1], values[0], values[2],values[0], values[8]) #abs Error mit Vs46 # plot(values[0], values[4], values[0], values[5],'red') #taxiAnz47 xticks(range(0, 86400 + 3600, 3600 * 2), range(0, 25, 2), size=textsize)48 axis([axis()[0], 86400, axis()[2], axis()[3]])49 yticks(size=textsize)50 subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)51 #xlabel("t (s)", size=textsize)52 xlabel(53 "\nt [h] (Aggregationsintervall=" + str(interval) + "s)", size=textsize)54 #ylabel("v [km/h]", size=textsize)55 ylabel("relative Abweichung [%]", size=textsize)56 #ylabel("absolute Abweichung [km/h]", size=textsize)57 #ylabel("Anzahl der Fahrzeuge",size=textsize)58 # legend(legendText)59 # legend(('FCD','simFCD','simFCD-FCD',))60 #legend(('reale FCD','sim. FCD'))61def getDataForTaxi(taxiId):62 """Gets the Data for a single Taxi"""63 values = [[], [], [], [], [], []] # x1,y1,x2,y2,x3,y364 starttime = 065 taxis = reader.readAnalysisInfo(WEE)66 for step in taxis[taxis.index(taxiId)].getSteps():67 if step.source == SOURCE_FCD:68 values[0].append(step.time - starttime)69 values[1].append(step.speed)70 elif step.source == SOURCE_SIMFCD:71 values[2].append(step.time - starttime)72 values[3].append(step.speed)73 elif step.source == SOURCE_VTYPE:74 if starttime == 0:75 starttime = step.time76 values[4].append(step.time - starttime)77 values[5].append(step.speed)78 return (values, starttime)79def getAveragedValues(interval):80 """catches all data in the given interval steps and calculates the average speed for each interval."""81 timeValues = range(0, 86410, interval)82 fcdValues = [[] for i in range(0, 86410, interval)]83 simFcdValues = [[] for i in range(0, 86410, interval)]84 vtypeValues = [[] for i in range(0, 86410, interval)]85 relErrorValues = [[] for i in range(0, 86410, interval)]86 absErrorValues = [[] for i in range(0, 86410, interval)]87 fcdValuesNo = [set() for i in range(0, 86410, interval)]88 simFcdValuesNo = [set() for i in range(0, 86410, interval)]89 vtypeValuesNo = [set() for i in range(0, 86410, interval)]90 taxis = reader.readAnalysisInfo(WEE)91 # helper function92 def calcAverageOrLen(list, no=False):93 for i in range(len(list)):94 if len(list[i]) > 0:95 if no: # if no True clac Len96 list[i] = len(list[i])97 else:98 list[i] = sum(list[i]) / len(list[i])99 else:100 list[i] = None101 return list102 for taxi in taxis:103 for step in taxi.getSteps():104 if step.source == SOURCE_FCD:105 # add the speed to the corresponding time interval106 fcdValues[step.time / interval].append(step.speed)107 fcdValuesNo[step.time / interval].add(taxi.id)108 elif step.source == SOURCE_SIMFCD:109 # add the speed to the corresponding time interval110 simFcdValues[step.time / interval].append(step.speed)111 simFcdValuesNo[step.time / interval].add(taxi.id)112 elif step.source == SOURCE_VTYPE:113 # add the speed to the corresponding time interval114 vtypeValues[step.time / interval].append(step.speed)115 vtypeValuesNo[step.time / interval].add(taxi.id)116 vtypeValues = calcAverageOrLen(vtypeValues)117 fcdValues = calcAverageOrLen(fcdValues)118 simFcdValues = calcAverageOrLen(simFcdValues)119 vtypeValuesNo = calcAverageOrLen(vtypeValuesNo, True)120 fcdValuesNo = calcAverageOrLen(fcdValuesNo, True)121 simFcdValuesNo = calcAverageOrLen(simFcdValuesNo, True)122 # calc relative Error123 for i in range(len(fcdValues)):124 if simFcdValues[i] == None or fcdValues[i] == None:125 relErrorValues[i] = None126 absErrorValues[i] = None127 else:128 #(angezeigter-richtiger Wert)129 absErr = simFcdValues[i] - fcdValues[i]130 relErrorValues[i] = absErr / float(fcdValues[i]) * 100131 absErrorValues[i] = absErr132 return ([timeValues, fcdValues, simFcdValues, vtypeValues, fcdValuesNo, simFcdValuesNo, vtypeValuesNo, relErrorValues, absErrorValues], interval)133# start the program134# profile.run('main()')...
summary.py
Source:summary.py
...36 self._interleaved_computed_per_page_values_and_summaries = []37 self._key_func = key_func38 self._ComputePerPageValues(all_page_specific_values)39 @property40 def computed_per_page_values(self):41 return self._computed_per_page_values42 @property43 def computed_summary_values(self):44 return self._computed_summary_values45 @property46 def interleaved_computed_per_page_values_and_summaries(self):47 """Returns the computed per page values and summary values interleaved.48 All the results for a given name are printed together. First per page49 values, then summary values.50 """51 return self._interleaved_computed_per_page_values_and_summaries52 def _ComputePerPageValues(self, all_page_specific_values):53 all_successful_page_values = [54 v for v in all_page_specific_values if not (isinstance(55 v, failure.FailureValue) or isinstance(v, skip.SkipValue))]56 # We will later need to determine how many values were originally created57 # for each value name, to apply a workaround meant to clean up the printf...
views.py
Source:views.py
1from django.shortcuts import render2from django.http import HttpResponse,Http4043from mysite.cricbuzz import Cricbuzz4from mysite.forms import *5from . import gen as ge6from mysite.models import *7def index(request):8 return render(request,'mysite/homepage/index.html')9def livescore(request):10 c = Cricbuzz()11 dic= {}12 matches = c.matches()13 if not matches:14 return HttpResponse("can't connect to cricbzz.com......")15 for match in matches:16 #print (match)17 if(match['matchstate'] != 'nextlive'):18 #print (dic)19 dic[match['id']] = (c.livescore(match['id']))20 #print (c.commentary(match['id']))21 #print (c.scorecard(match['id']))22 #print(dic)23 return render(request,'mysite/Livescore/livescore.html',{'matches':dic})24#def livematch(request,mid):25# return render(request,'')26def compare(request):27 if request.method == 'GET':28 dit = {}29 p_dict = {}30 if 'player1' in request.GET:31 player1 = request.GET['player1']32 player1 = Player.objects.get(name=player1) 33 values = player1.get_attrb()34 p_dict = {35 'name':values[0],'team':values[12],'Runs':values[1],'fiftys':values[2],'hundreds':values[3],'matchplayed':values[4],'average':values[5],36 'run_rate':values[6],'HighScore':values[7],'overs':values[8],'wickets':values[9],'economy':values[10],'wicket_streak':values[11]37 }38 print(p_dict)39 dit['player1'] = p_dict40 if 'player2' in request.GET:41 if request.GET['player2']:42 player2 = request.GET['player2']43 print(player2)44 player2 = Player.objects.get(name=player2) 45 values = player2.get_attrb()46 p_dict = {47 'name':values[0],'team':values[12],'Runs':values[1],'fiftys':values[2],'hundreds':values[3],'matchplayed':values[4],'average':values[5],48 'run_rate':values[6],'HighScore':values[7],'overs':values[8],'wickets':values[9],'economy':values[10],'wicket_streak':values[11]49 }50 print(p_dict)51 dit['player2'] = p_dict52 if 'player3' in request.GET:53 if request.GET['player3']:54 player3 = request.GET['player3']55 print(player3)56 player3 = Player.objects.get(name=player3) 57 values = player3.get_attrb()58 p_dict = {59 'name':values[0],'team':values[12],'Runs':values[1],'fiftys':values[2],'hundreds':values[3],'matchplayed':values[4],'average':values[5],60 'run_rate':values[6],'HighScore':values[7],'overs':values[8],'wickets':values[9],'economy':values[10],'wicket_streak':values[11]61 }62 print(p_dict)63 dit['player3'] = p_dict64 if 'player4' in request.GET and request.GET['player4']:65 if request.GET['player4']:66 player4 = request.GET['player4']67 player4 = Player.objects.get(name=player4) 68 values = player4.get_attrb()69 p_dict = {70 'name':values[0],'team':values[12],'Runs':values[1],'fiftys':values[2],'hundreds':values[3],'matchplayed':values[4],'average':values[5],71 'run_rate':values[6],'HighScore':values[7],'overs':values[8],'wickets':values[9],'economy':values[10],'wicket_streak':values[11]72 }73 print(p_dict)74 dit['player4'] = p_dict75 return render(request,'mysite/Compare.html',dit) 76def matches(request):77 match = Match.objects.all()78 matchs_dict = {'matches':match}79 return render(request,'mysite/match/matches.html',matchs_dict)80def match(request,pk):81 try:82 obj = Match.objects.get(id=pk)83 values = obj.get_attrb()84 match_dict = {'team1':values[0],'team2':values[1],'type':values[2],'batting1':values[3].get_attrb(),'batting2':values[4].get_attrb(),'bowling1':values[5].get_attrb(),'bowling2':values[6].get_attrb()}85 c = ge.Statistics()86 c.generate()87 return render(request,'mysite/match/match.html',match_dict)88 except Match.DoesNotExist:89 raise Http404("Match does not Exist.....")90def getScores(request):91 pass; 92def player(request,player_name):93 try:94 p = Player.objects.get(name=player_name)95 values = p.get_attrb()96 player_dict = {97 'name':values[0],'team':values[12],'Runs':values[1],'fiftys':values[2],'hundreds':values[3],'matchplayed':values[4],'average':values[5],98 'run_rate':values[6],'HighScore':values[7],'overs':values[8],'wickets':values[9],'economy':values[10],'wicket_streak':values[11]99 }100 return render(request,'mysite/player/player.html',player_dict)101 except Player.DoesNotExist:102 raise Http404("Player does not Exist.....")103#def team(request):104 105def about(request):106 return render(request,'mysite/about.html',{'about':'About Us','news':['We are a gang of two people','who steal scores from cricbuzz.']})...
manage.py
Source:manage.py
1#Loads a list of the rows in the file f, splitting on the spaces2def LoadData(fname):3 f=open(fname,'r')4 data=[]5 for line in f.readlines():6 data.append(line.replace('\n','').split(' '))7 f.close()8 return data9#Loads a list of the rows in the file f, splitting on the double spaces10def LoadDataSpaces(fname):11 f=open(fname,'r')12 data=[]13 for line in f.readlines():14 data.append(line.replace('\n','').split(' '))15 f.close()16 return data17#Loads a list of the rows in the file f, splitting on the tabs18def LoadDataTab(fname):19 f=open(fname,'r')20 data=[]21 for line in f.readlines():22 data.append(line.replace('\n','').split('\t'))23 f.close()24 return data25def LoadDataHyphen(fname):26 f=open(fname,'r')27 data=[]28 for line in f.readlines():29 data.append(line.replace('\n','').split('-'))30 f.close()31 return data32#Used in conjunction with LoadData to pull out a column of a file as a list33#of floats34def IterativeFloatAppend(values,index):35 new_list=[]36 for i in range(len(values)):37 point=float(values[i][index])38 new_list.append(point)39 return new_list40#Used in conjunction with LoadData to pull out a column of a file as a list41#of integers42def IterativeIntAppend(values,index):43 new_list=[]44 for i in range(len(values)):45 point=int(values[i][index])46 new_list.append(point)47 return new_list48#Used in conjunction with LoadData to pull out a column of a file as a list49#of strings50def IterativeStrAppend(values,index):51 new_list=[]52 for i in range(len(values)):53 point=str(values[i][index])54 new_list.append(point)55 return new_list56#Find the differences in consecutive values of a list57def Differences(values):58 new_list=[]59 for i in range((len(values))-1):60 point=values[i+1]-values[i]61 new_list.append(point)62 return new_list63#Remove repeats from a list of values64def RemoveRepeats(values):65 new_list=[]66 for i in range(len(values)):67 if values[i] not in new_list:68 new_list.append(values[i])69 return new_list70#Write a list to file as a column71def WriteFile(values,fname):72 with open(fname,"w") as data:73 for i in range(len(values)):74 data.write("{0}\n".format(values[i]))75def WriteFile2Cols(values1,values2,fname):76 with open(fname,"w") as data:77 for i in range(len(values1)):78 data.write("{0} {1}\n".format(values1[i],values2[i]))79def WriteFileCols(values,fname):80 with open(fname,"w") as data:81 for i in range(len(values)):82 data.write("{0} {1}\n".format(values[i][0],values[i][1]))83def WriteFile3Cols(values,fname):84 with open(fname,"w") as data:85 for i in range(len(values)):86 data.write("{0} {1} {2}\n".format(values[i][0],values[i][1],values[i][2]))87def WriteFile5Cols(values,fname):88 with open(fname,"w") as data:89 for i in range(len(values)):90 data.write("{0} {1} {2} {3} {4}\n".format(values[i][0],values[i][1],values[i][2],values[i][3],values[i][4]))91def WriteFile4Cols(values,fname):92 with open(fname,"w") as data:93 for i in range(len(values)):94 data.write("{0} {1} {2} {3}\n".format(values[i][0],values[i][1],values[i][2],values[i][3]))95def WriteFile6Cols(values,fname):96 with open(fname,"w") as data:97 for i in range(len(values)):98 data.write("{0} {1} {2} {3} {4} {5}\n".format(values[i][0],values[i][1],values[i][2],values[i][3],values[i][4],values[i][5]))99def WriteFile7Cols(values,fname): 100 with open(fname,"w") as data:101 for i in range(len(values)):102 data.write("{0} {1} {2} {3} {4} {5} {6}\n".format(values[i][0],values[i][1],values[i][2],values[i][3],values[i][4],values[i][5],values[i][6]))103def WriteFile8Cols(values,fname):104 with open(fname,"w") as data:105 for i in range(len(values)):...
Using AI Code Generation
1import {createMock} from 'ts-auto-mock';2const mock = createMock<Interface1>();3console.log(mock);4import {createMock} from 'ts-auto-mock';5const mock = createMock<Interface1>();6console.log(mock);75 const mock = createMock();8 5 const mock = createMock();
Using AI Code Generation
1import {mock} from 'ts-auto-mock';2interface Test {3 a: string;4 b: number;5}6const test: Test = mock<Test>();7console.log(test.a);8console.log(test.b);9import {mock} from 'ts-auto-mock';10interface Test {11 a: string;12 b: number;13}14const test: Test = mock<Test>();15console.log(test.a);16console.log(test.b);17import {mock} from 'ts-auto-mock';18interface Test {19 a: string;20 b: number;21}22const test: Test = mock<Test>();23console.log(test.a);24console.log(test.b);25import {mock} from 'ts-auto-mock';26interface Test {27 a: string;28 b: number;29}30const test: Test = mock<Test>();31console.log(test.a);32console.log(test.b);33import {mock} from 'ts-auto-mock';34interface Test {35 a: string;36 b: number;37}38const test: Test = mock<Test>();39console.log(test.a);40console.log(test.b);41import {mock} from 'ts-auto-mock';42interface Test {43 a: string;44 b: number;45}46const test: Test = mock<Test>();47console.log(test.a);48console.log(test.b);49import {mock} from 'ts-auto-mock';50interface Test {51 a: string;52 b: number;53}54const test: Test = mock<Test>();55console.log(test.a);56console.log(test.b);57import {mock} from 'ts-auto-mock';58interface Test {59 a: string;60 b: number;61}62const test: Test = mock<Test>();63console.log(test.a);64console.log(test.b);65import {
Using AI Code Generation
1import { values } from 'ts-auto-mock';2const obj = { a: 1, b: 2, c: 3 };3const vals = values(obj);4console.log(vals);5import { values } from 'lodash';6const obj = { a: 1, b: 2, c: 3 };7const vals = values(obj);8console.log(vals);9const obj = { a: 1, b: 2, c: 3 };10const vals = Object.values(obj);11console.log(vals);
Using AI Code Generation
1import {Values} from 'ts-auto-mock/extension';2export type MyType = {3 name: string;4 surname: string;5 age: number;6};7const values: Values<MyType> = {8};9import {Values} from 'ts-auto-mock/extension';10export type MyType = {11 name: string;12 surname: string;13 age: number;14};15const values: Values<MyType> = {16};17import {Values} from 'ts-auto-mock/extension';18export type MyType = {19 name: string;20 surname: string;21 age: number;22};23const values: Values<MyType> = {24};25import {Values} from 'ts-auto-mock/extension';26export type MyType = {27 name: string;28 surname: string;29 age: number;30};31const values: Values<MyType> = {32};33import {Values} from 'ts-auto-mock/extension';34export type MyType = {35 name: string;36 surname: string;37 age: number;38};39const values: Values<MyType> = {40};41import {Values} from 'ts-auto-mock/extension';42export type MyType = {43 name: string;44 surname: string;45 age: number;46};47const values: Values<MyType> = {48};49import {Values} from '
Using AI Code Generation
1import {values} from 'ts-auto-mock';2const mock = values({3});4console.log(mock);5import {values} from 'ts-auto-mock';6const mock = values([7]);8console.log(mock);9import {values} from 'ts-auto-mock';10const mock = values(11);12console.log(mock);13import {values} from 'ts-auto-mock';14const mock = values(15);16console.log(mock);17import {values} from 'ts-auto-mock';18const mock = values(19);20console.log(mock);21import {values} from 'ts-auto-mock';22const mock = values(23);24console.log(mock);25import {values} from 'ts-auto-mock';26const mock = values(27);28console.log(mock);29import {values} from 'ts-auto-mock';30const mock = values(31 Symbol('test')32);33console.log(mock);34import {values} from 'ts-auto-mock';35const mock = values(36);37console.log(mock);
Using AI Code Generation
1import { Values } from 'ts-auto-mock';2import { Values } from 'ts-auto-mock';3import { Values } from 'ts-auto-mock';4import { Values } from 'ts-auto-mock';5import { Values } from 'ts-auto-mock';6import { Values } from 'ts-auto-mock';7import { Values } from 'ts-auto-mock';8import { Values } from 'ts-auto-mock';9import { Values } from 'ts-auto-mock';
Using AI Code Generation
1import { values } from 'ts-auto-mock';2interface TestInterface {3 property: string;4}5const test: TestInterface = values<TestInterface>();6console.log(test.property);7import { values } from 'ts-auto-mock';8interface TestInterface {9 property: string;10}11const test: TestInterface = values<TestInterface>();12console.log(test.property);13import { values } from 'ts-auto-mock';14interface TestInterface {15 property: string;16}17const test: TestInterface = values<TestInterface>();18console.log(test.property);19import { values } from 'ts-auto-mock';20interface TestInterface {21 property: string;22}23const test: TestInterface = values<TestInterface>();24console.log(test.property);25import { values } from 'ts-auto-mock';26interface TestInterface {27 property: string;28}29const test: TestInterface = values<TestInterface>();30console.log(test.property);31import { values } from 'ts-auto-mock';32interface TestInterface {33 property: string;34}35const test: TestInterface = values<TestInterface>();36console.log(test.property);37import { values } from 'ts-auto-mock';38interface TestInterface {39 property: string;40}41const test: TestInterface = values<TestInterface>();42console.log(test.property);43import { values } from 'ts-auto-mock';44interface TestInterface {45 property: string;46}47const test: TestInterface = values<TestInterface>();48console.log(test.property);49import {
Using AI Code Generation
1const { values } = require("ts-auto-mock");2const { Property } = require("./test2");3const property = values<Property>();4console.log(property);5exports.Property = {6 properties: {7 },8};9{ name: 'Property', properties: { name: 'string', address: 'string', price: 'number' } }
Using AI Code Generation
1import { values } from 'ts-auto-mock';2const obj = {3};4const valuesObj = values(obj);5import { values } from 'ts-auto-mock';6const obj = {7};8const valuesObj = values(obj);
Using AI Code Generation
1import { values } from 'ts-auto-mock';2const result = values(1);3console.log(result);4import { values } from 'ts-auto-mock';5const result = values('1');6console.log(result);7import { values } from 'ts-auto-mock';8const result = values({});9console.log(result);10import { values } from 'ts-auto-mock';11const result = values([]);12console.log(result);13import { values } from 'ts-auto-mock';14const result = values([1, 2]);15console.log(result);16import { values } from 'ts-auto-mock';17const result = values([1, '2']);18console.log(result);19import { values } from 'ts-auto-mock';20const result = values([1, '2', {}]);21console.log(result);22import { values } from 'ts-auto-mock';23const result = values([1, '2', {}, []]);24console.log(result);25import { values } from 'ts-auto-mock';
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!