예제 #1
0
def xPPMT(rate=0, per=0, nper=0, pv=0, fv=0, type1=0):
    # 一直用等额本金  默认0
    per = check_value(type(per))(per)
    if per == 0:
        return 0
    rate = check_value(type(rate))(rate)
    nper = check_value(type(nper))(nper)
    pv = check_value(type(pv))(pv)
    fv = check_value(type(fv))(fv)
    try:
        a = numpy.ppmt(rate, per, nper, pv, fv)
    except:
        a = 0
    return a
예제 #2
0
 def __init__(self, NN, sigma, km_filepath='./data/color_bins/pts_in_hull.npy', cc=-1):
     if(util.check_value(cc, -1)):
         self.cc = np.load(km_filepath)
     else:
         self.cc = cc
     self.K = self.cc.shape[0]
     self.NN = int(NN)
     self.sigma = sigma
     self.nbrs = nn.NearestNeighbors(n_neighbors=self.NN, algorithm='auto').fit(self.cc)
 def __init__(self, NN, sigma, km_filepath='/shared/foss/interactive-deep-colorization/data/color_bins/pts_in_hull.npy', cc=-1):
     if(util.check_value(cc, -1)):
         self.cc = np.load(km_filepath)
     else:
         self.cc = cc
     self.K = self.cc.shape[0]
     self.NN = int(NN)
     self.sigma = sigma
     self.nbrs = nn.NearestNeighbors(n_neighbors=self.NN, algorithm='auto').fit(self.cc)
def go(filename, address, categories=None, walking_time=None, full_info=False):
    '''
    Process the raw data and run the whole program.
    Inputs:
        filename: (str) filename of the data
        address:(str) address of user
        categories: (list of strings) the list of attempted service types
        walking_time: (int) the desired maximum walking time
        full_info: (boolean) whether or not to return the full information
    '''
    try:
        pd.options.display.max_colwidth = 650
        df = pd.read_csv(filename, dtype=COL_TYPES, index_col=0)
    except IOError:
        print("Could not read file: {}".format(filename))
    assert util.check_value(address, categories, walking_time, full_info) \
                                                    is True, 'Value Error!'

    df, dict_of_geocode = get_nearest_spots(\
      df, address, categories, walking_time, full_info)
    map_url = map_plot(address, dict_of_geocode)
    export_output(df, map_url, address)
예제 #5
0
파일: LaSilla.py 프로젝트: vbonvin/POUET
 def get(self, debugmode, FLAG = -9999):
     """
     Get method that reads the weather reports off the web. In the LaSilla case, it download a `meteo.last` and interprets the data.
     
     :param debugmode: whether or not POUET is in debugmode. If true, it ought to return some static and dummy data
     :param FLAG: what to return in case the weather report cannot be downloaded or treated. Currently, POUET expect -9999 as a placeholder.
 
     :return: Wind direction, speed, temperature and humidity
     
     .. warning:: Such a method *must* return the following variables in that precise order: wind direction, wind speed, temperature and humidity
     
     """
     #todo: add a "no connection" message if page is not reachable instead of an error
     WS=[]
     WD=[]
     RH = None
     Temps = []
     
     error_msg = "Cannot download weather data. Either you or the weather server is offline!"
     
     if debugmode:
         fname = os.path.join(os.path.dirname(os.path.abspath(inspect.stack()[0][1])), "meteoDebugMode.last")
         fi = open(fname, mode='r')
         data = ""
         with fi:
             line = fi.read()
             data += line
     else:
         try:
             #data=urllib.request.urlopen(self.location.get("weather", "url")).read()
             data = requests.get(self.config.get("weather", "url")).content
         except requests.ConnectionError:
             logger.warning(error_msg)
             return FLAG, FLAG, FLAG, FLAG
         
         data = data.decode("utf-8")
         if "404 Not Found" in data:
             logger.warning(error_msg)
             return FLAG, FLAG, FLAG, FLAG
         
     data=data.split("\n") # then split it into lines
     for line in data:
         if re.match( r'WD', line, re.M|re.I):
             WD.append(int(line[20:25])) # AVG
         if re.match( r'WS', line, re.M|re.I):
             WS.append(float(line[20:25])) # AVG
         if re.match( r'RH', line, re.M|re.I):
             RH = float(line[20:25]) # AVG
         if re.match( r'T ', line, re.M|re.I):
             Temps.append(float(line[20:25])) # AVG
 
     # Remove out-of-band readings
     # WD is chosen between station 1 or 2 in EDP pour la Silla.
     # We take average
     Temps = np.asarray(Temps, dtype=np.float)
     Temps = Temps[Temps < 100]
     Temps = np.mean(Temps)
 
     # Remove out-of-band readings
     # WD is chosen between station 1 or 2 in EDP pour la Silla.
     # We take average
     WD = np.asarray(WD, dtype=np.float)
     WD = WD[WD < 360]
     WD = WD[WD > 0]
     WD = np.mean(WD)
     
     # WS should be either WS next to 3.6m or max
     # Remove WS > 99 m/s
     WS = np.asarray(WS, dtype=np.float)
     if WS[2] < 99:
         WS = WS[2]
     else:
         logger.warning("Wind speed from 3.6m unavailable, using other readings in LaSilla")
         WS = np.asarray(WS, dtype=np.float)
         WS = WS[WS > 0]
         WS = WS[WS < 99]
         WS = np.mean(WS)
 
     for var in [WD, WS, Temps, RH]:
         if not np.isnan(var):
             var = -9999
     
     WD = util.check_value(WD, FLAG)
     WS = util.check_value(WS, FLAG)
     Temps = util.check_value(Temps, FLAG)
     RH = util.check_value(RH, FLAG)
     
     return WD, WS, Temps, RH
예제 #6
0
    def eng(self, value: str, sheet: str, old_value: str = "A1", count_func=0):
        # 主要逻辑函数
        # print(sheet + "\t" + old_value + "\t" + str(value) + "\t")
        if isinstance(value, str) and value.startswith("="):
            if sheet == "财报":
                if self.end_time(old_value):
                    return 0

            # 遇见返回行 解析当前坐标并替换函数
            if "COLUMN()" in value:
                r, c = ret_row_column(old_value)
                value = value.replace("COLUMN()", str(c))

            if "%" in value:
                value = percentile_tu_float(value)
            try:
                val = self.format_parser(value, sheet)
                self.set_temp_data(old_value, val, sheet)
                self.set_date(old_value, val, sheet)
                return val
            except:
                # print(sheet + "\t" + old_value + "\t" + str(value) + "\t")
                pass
            if old_value == "输出":
                old_value = "A1"
            reference = ""
            source_r, source_c = ret_row_column(old_value)
            if sheet != "财报" or (sheet == "财报" and
                                 (source_c < 8 or
                                  (source_c >= 8 and count_func != 0))):
                # 解析函数
                func = formulas.Parser().ast(value)[1].compile()
                func_inputs = func.inputs
                #  遇见偏移函数,解析偏移标示位
                if "OFFSET" in func.outputs[0]:
                    str_o = func.outputs[0]
                    sps = str_o.split("OFFSET(")[1]
                    reference = sps.split(",")[0]
            else:
                count_func += 1
                # 读取解析好的函数
                func = self.func_dic[source_r]
                # 判断是否是最后一个值
                jianshe_time = self.get_temp_data("E230", "假设表")
                end_time = jianshe_time + 240 + 12 + 7
                source_c_char = row_list[source_c]
                source_c_char_1 = row_list[source_c - 1]
                source_c_char__1 = row_list[source_c + 1]
                func_inputs = []
                if source_c == end_time and (source_r in [
                        228, 254, 260, 265, 270, 275, 280, 287, 292, 297, 302
                ]):
                    func = self.func_dic["if_func"]
                    for i in func.inputs:
                        if i == "A1":
                            i = source_c_char + str(source_r - 2)
                        if i == "A2":
                            i = source_c_char + str(source_r - 1)
                        if i == "H18":
                            i = source_c_char + "18"
                        func_inputs.append(i)
                elif source_r == 530 and source_c > 8:
                    func = self.func_dic["I530"]
                    func_inputs.append(source_c_char_1 + "530")
                else:
                    func_outputs = func.outputs[0]
                    if source_r == 217:
                        for i in func.inputs:
                            if i == "H217":
                                func_inputs.append("H217:" + source_c_char_1 +
                                                   "217")
                                continue
                            new_input = list(i)
                            for i, v in enumerate(i):
                                if v == "I":
                                    new_input[i] = source_c_char
                            func_inputs.append("".join(new_input))
                        if "OFFSET" in func_outputs:
                            str_o = func_outputs
                            sps = str_o.split("OFFSET(")[1]
                            reference = list(sps.split(",")[0])
                            for i, v in enumerate(reference):
                                if v == "I":
                                    reference[i] = source_c_char
                            reference = "".join(reference)
                    else:
                        for i in func.inputs:
                            sums = self.ret_sum(source_r, i, source_c_char,
                                                source_c_char_1,
                                                source_c_char__1)
                            if sums:
                                func_inputs.append(sums)
                                continue

                            new_input = list(i)
                            for i, v in enumerate(i):
                                if v == "H":
                                    new_input[i] = source_c_char
                                if v == "G":
                                    new_input[i] = source_c_char_1
                                if v == "I":
                                    new_input[i] = source_c_char__1
                            func_inputs.append("".join(new_input))
                        if "OFFSET" in func_outputs:
                            str_o = func_outputs
                            sps = str_o.split("OFFSET(")[1]
                            reference = list(sps.split(",")[0])
                            for i, v in enumerate(reference):
                                if v == "H":
                                    reference[i] = source_c_char
                                if v == "G":
                                    reference[i] = source_c_char_1
                                if v == "I":
                                    reference[i] = source_c_char__1
                            reference = "".join(reference)

            inputs = []
            for input in func_inputs:
                res = self.input_func(sheet, reference, input, old_value)
                inputs.append(res)

            val = self.eng(func(*inputs), sheet, old_value)
            if isinstance(val, str) and val.startswith("="):
                val = self.eng(val, sheet, old_value, count_func=count_func)
            return val
        else:
            # print("写入")
            # 假设表 其他机组类型为空时设置0
            if not value and sheet != "假设表" or (sheet == "假设表" and
                                                (old_value == "E19"
                                                 or old_value == "E20")):
                value = 0
            if str(value) == "#VALUE!" or str(value) == "#REF!" or str(value) == "0" or str(value) == "[[#VALUE!]]" \
                    or str(value) == "#DIV/0!":
                value = 0
            if (old_value == "H195" or old_value == "E247" or old_value == "E246") \
                    and sheet == "假设表" and value == "":
                value = 0
            if (old_value == "E41" or old_value == "E247" or old_value == "E246") \
                    and sheet == "假设表" and value == "":
                value = 0

            # print(sheet + "\t" + old_value + "\t" + str(value) + "\t")
            value = check_value(type(value))(value)
            self.set_temp_data(old_value, value, sheet)
            self.set_date(old_value, value, sheet)
            if "A1" == old_value:
                self.save_all_data()
            # if sum_count == (2 + save_count) * 10000:
            #     save_count += 2
            #     save_all_data()
            return value
예제 #7
0
    def input_func(self,
                   sheet=None,
                   reference=None,
                   input=None,
                   old_value=None):
        # 返回input输入参数函数
        if reference and input == reference:
            # 遇见OFFSET时设置标志位跳过当前位
            return reference
        if "!" in input:
            # 遇见表跳转解析 ’!‘
            new_sheet = input.split("!")[0]
            new_sheet = new_sheet.replace("'", "")
            input = input.split("!")[1]
        else:
            # 赋值表名不变
            new_sheet = sheet

        if ":" in input:
            sum_sss = self.get_temp_data(input, new_sheet)
            if sum_sss == -999999:
                # 创建循环
                start = input.split(":")[0]
                end = input.split(":")[1]
                # 解析循环的开始和结束
                start_column, start_row = get_row_column(start)
                end_column, end_row = get_row_column(end, "")
                start_column_list = get_list_row(start_column)
                end_column_list = get_list_row(end_column)
                sum_sss = []
                for i in range(start_row, end_row + 1):
                    rows = []
                    for j in [
                            item for item in end_column_list
                            if not item in start_column_list[:-1]
                    ]:
                        val = self.get_temp_data(j + str(i), new_sheet)
                        if val == -999999:
                            val = self.eng(self.get_date_value(
                                j + str(i), new_sheet),
                                           new_sheet,
                                           old_value=j + str(i))
                        if isinstance(val, str) and val.startswith("="):
                            val = self.eng(val, new_sheet, j + str(i))
                        val = check_value(type(val))(val)
                        rows.append(val)
                        # 添加循环出来的每一个值
                        self.set_temp_data(j + str(i), val, new_sheet)
                        self.set_date(j + str(i), val, new_sheet)
                    sum_sss.append(rows)
                if len(sum_sss) == 1:
                    sum_sss = sum_sss[0]
                self.set_temp_data(input, sum_sss, new_sheet)
            sum_sss = np.array(sum_sss)
            return sum_sss
        else:
            val = self.get_temp_data(input, new_sheet)
            if val == -999999 or (isinstance(val, str)
                                  and val.startswith("=")):
                # 普通数据时直接去解析坐标的值
                val = self.eng(self.get_date_value(input, new_sheet),
                               new_sheet, input)
                if isinstance(val, str) and val.startswith("="):
                    val = self.eng(val, new_sheet, input)
            val = check_value(type(val))(val)
            self.set_temp_data(input, val, new_sheet)
            self.set_date(input, val, new_sheet)
            return val
예제 #8
0
    def get(self, debugmode, FLAG=-9999):
        """
        Get method that reads the weather reports off the web. In the LaSilla case, it download a `meteo.last` and interprets the data.
        
        :param debugmode: whether or not POUET is in debugmode. If true, it ought to return some static and dummy data
        :param FLAG: what to return in case the weather report cannot be downloaded or treated. Currently, POUET expect -9999 as a placeholder.
    
        :return: Wind direction, speed, temperature and humidity
        
        .. warning:: Such a method *must* return the following variables in that precise order: wind direction, wind speed, temperature and humidity
        
        """
        #todo: add a "no connection" message if page is not reachable instead of an error
        WS = []
        WD = []
        RH = None
        Temps = []

        error_msg = "Cannot download weather data. Either you or the weather server is offline!"

        if debugmode:
            fname = os.path.join(
                os.path.dirname(os.path.abspath(inspect.stack()[0][1])),
                "meteoDebugMode.last")
            fi = open(fname, mode='r')
            data = ""
            with fi:
                line = fi.read()
                data += line
        else:
            try:
                #data=urllib.request.urlopen(self.location.get("weather", "url")).read()
                data = requests.get(self.config.get("weather", "url")).content
            except requests.ConnectionError:
                logger.warning(error_msg)
                return FLAG, FLAG, FLAG, FLAG

            data = data.decode("utf-8")
            if "404 Not Found" in data:
                logger.warning(error_msg)
                return FLAG, FLAG, FLAG, FLAG

        data = data.split("\n")  # then split it into lines
        for line in data:
            if re.match(r'WD', line, re.M | re.I):
                WD.append(int(line[20:25]))  # AVG
            if re.match(r'WS', line, re.M | re.I):
                WS.append(float(line[20:25]))  # AVG
            if re.match(r'RH', line, re.M | re.I):
                RH = float(line[20:25])  # AVG
            if re.match(r'T ', line, re.M | re.I):
                Temps.append(float(line[20:25]))  # AVG

        # Remove out-of-band readings
        # WD is chosen between station 1 or 2 in EDP pour la Silla.
        # We take average
        Temps = np.asarray(Temps, dtype=np.float)
        Temps = Temps[Temps < 100]
        Temps = np.mean(Temps)

        # Remove out-of-band readings
        # WD is chosen between station 1 or 2 in EDP pour la Silla.
        # We take average
        WD = np.asarray(WD, dtype=np.float)
        WD = WD[WD < 360]
        WD = WD[WD > 0]
        WD = np.mean(WD)

        # WS should be either WS next to 3.6m or max
        # Remove WS > 99 m/s
        WS = np.asarray(WS, dtype=np.float)
        if WS[2] < 99:
            WS = WS[2]
        else:
            logger.warning(
                "Wind speed from 3.6m unavailable, using other readings in LaSilla"
            )
            WS = np.asarray(WS, dtype=np.float)
            WS = WS[WS > 0]
            WS = WS[WS < 99]
            WS = np.mean(WS)

        for var in [WD, WS, Temps, RH]:
            if not np.isnan(var):
                var = -9999

        WD = util.check_value(WD, FLAG)
        WS = util.check_value(WS, FLAG)
        Temps = util.check_value(Temps, FLAG)
        RH = util.check_value(RH, FLAG)

        return WD, WS, Temps, RH