Code Monkey home page Code Monkey logo

borax's People

Contributors

fastpx2014 avatar kinegratii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

borax's Issues

农历:LunarDate.cn_day_calendar 计算错误%F 描述符缺少“月”后缀

问题类型

  • BUG
  • 新功能
  • 功能优化

问题

LunarDate.cn_day_calendar 计算错误,同时 '%F' 描述符计算错误。

代码

from borax.calendars import LunarDate, LCalendars
print([LunarDate(year=2017, month=month, day=1, leap=leap).cn_day_calendar for month, days, leap in LCalendars.iter_year_month(2017)])

结果为

['正', '二', '三', '四', '五', '六', '六', '七', '八', '九', '十', '冬', '腊']

正确结果为


['正月', '二月', '三月', '四月', '五月', '六月', '闰六', '七月', '八月', '九月', '十月', '冬月', '腊月']

需要帮助:获取今年生日的阳历日期

目前打算开发一个生日计算功能的小脚本,根据阳历出生年月日,然后推算今年什么时候过阴历生日,目前试了很多的农历Python库,但是没有找到一个很好的解决办法,而且还涉及到闰月的情况,我还不太清楚闰月发生时,是要过两个生日么?

  • 根据出生年月日计算今年阴历生日
  • 当所处年份的生日月份存在闰月时如何处理

希望有能力的人能够帮助我一下,不胜感激 🙏

LunarDate.leap类型不一致

使用不同方法创建的 LunarDate 对象,其 leap 属性的类型有 boolint 之分,建议统一该属性类型。

例子:

>>>from borax.calendars import LunarDate
>>>ld = LunarDate.today()
>>>ld
 LunarDate(2020, 12, 15, 0)
>>>type(ld.leap)
<class 'int'>
>>> ld.leap
0
>>> ld2 = LunarDate(2020,12,15)
>>> ld2.leap
False
>>>type(ld.leap)
<class 'bool'>

festival2中文档与代码不一致

在官方文档中,有一个LeapConst类的描述。
而在borax.festival2模块中,没有LeapConst类。
可以在代码中添加,或修改描述。

Typing Hints优化

链接:https://peps.python.org/pep-0585/

从 python3.9开始,python类型注解支持使用内置的类型标识参数类型,而不必从 typing 导入。

比如在python3.9之前

from typing import List

def foo(a:List[int]):
    pass

python3.9之后可以这样使用

def foo(a:list[int]):
    pass

具体类型可查看 PEP 585。

v2.0.x Prospects

Features:

  • Remove deprecated packages and modules
  • Refactor documents
  • new modules
  • bugfix

Logic Error for serials

1 error in string format

el = len(exist_set)
if el + num > upper - lower:
raise ValueError('Can not generate {} serials in [(), {}].'.format(num, lower, upper))
if el == 0:

2 error for call super __init__

class StringSerialGenerator(SerialGenerator):
def __init__(self, prefix: str, digits: int = 2):
self._prefix = prefix
self._digits = digits
super().__init__(lower=0, upper=10 ** 2 - 1)

农历日“二十”“三十”中文名称错误

发现版本

v3.4.0

问题描述

“廿十”、“卅十” 是不正确的用法,因为“廿”、“卅” 本身就是二十、三十的意思了,正确的应该为“二十”、“三十”。

代码示例

from borax.calendars.lunardate import LunarDate, TextUtils

print(TextUtils.day_cn(20)) # “廿十”
ld = LunarDate(2020, 10, 20, 0)
print(ld.cn_day) # “廿十”
print(ld.cn_day_calendar) # “廿十”
print(ld.cn_str()) # “廿十”

建议方案

只需要修改 TextUtils.day_cn 逻辑即可,其他函数均是调用该函数。

[新版本]Borax 4.1.0

Borax 4.1.0 是一个重大更新的版本,主要包括:

  • python版本最低要求为3.9 ,不再支持python3.7和3.8
  • 使用 pyproject.toml 文件作为项目构建配置文件
  • 更新开发依赖包至最新版本,如flake8、nose2、pylint等
  • 新增基于 tkinter 的日历应用程序

预计发布时间:2024年1月

新增星期型节日(WeekFestival)的两种情形

下列两种节日按现有 WeekFestival 无法表示,建议添加。

index支持负数值,表示倒数

比如 ”国际麻风节“ 为 ”每年1月的最后一个星期日“。

WeekFestival(month=1, index=-1, week=calendar.SUNDAY, name='国际麻风节')

在编码上,原有的左起第4、5位表示序号(01-06)。引入负值index后,可用第4位表示是否倒数。上述“国际麻风节” 可表示如下:

201116

month支持取值0,表示每月

比如“每月第一个周日”,可表示如下:

WeekFestival(month=0, index=1, week=calendar.SUNDAY, freq=FreqConst.MONTHLY)

在编码表示如下:

200016

LCalendars.create_solar_date在2101年时出现错误

测试代码

d = LCalendars.create_solar_date(2101, term_name="小寒")
print(d) # 预期 2101-1-5

提示异常

  File "print_lunar.py", line 36, in te_temrs
    s = LCalendars.create_solar_date(2101, 1)
  File "E:\projects\borax\borax\calendars\lunardate.py", line 153, in create_solar_date
    _check_year_range(year)
  File "E:\projects\borax\borax\calendars\lunardate.py", line 35, in _check_year_range
    raise InvalidLunarDateError('[year={}]: Year must be in the range [1900, 2100]'.format(year))
borax.calendars.lunardate.InvalidLunarDateError: [year=2101]: Year must be in the range [1900, 2100]

fetch对列表数据无效

代码示例

from borax.datasets.fetch import fetch

points =  [
    ['a', 1, 3],
    ['b', 2, 4]
]

names, xs = fetch(points, 0, 1) # 预期 ['a', 'b'], [1,2]
names, xs = fetch(points, 0, 1, getter=lambda item, key: item[key])

代码执行错误

  File "E:\projects\demo.py", line 8, in fujian_area_bar
    names, xs = fetch(points, 0, 1)
  File "D:\py\lib\site-packages\borax\datasets\fetch.py", line 72, in fetch
    return list(ifetch(iterable, key, *keys, default=default, defaults=defaults, getter=getter))
  File "D:\py\lib\site-packages\borax\datasets\fetch.py", line 44, in _getter
    return partial(bget, key=key, default=default)(item)
  File "D:\py\lib\site-packages\borax\datasets\fetch.py", line 20, in bget
    return getattr(obj, key)
TypeError: getattr(): attribute name must be string

festivalfactory : 2017-08-21 day out of range

Only 2017-08-21 is day out of range, the other days are OK .

Test code:

import pandas as pd
from borax.calendars.festivals import FestivalFactory

factory = FestivalFactory(lang='zh-Hans')
dates = pd.date_range('2001-01-01', '2030-01-01')

for i in dates.date:
    try:
        factory.get_festival_names(i)
    except Exception as e:
        print(i, e)

新的节气型节日

节日示例

入梅 公历每年芒种之后第1个丙日 TermFestival(term='芒种', nth=1, day_gz='丙', name='入梅')
出梅 公历每年小暑之后第1个未日  TermFestival(term='小暑', nth=1, day_gz='未', name='出梅')
初伏 夏至后的第三个庚日 TermFestival(term='夏至', nth=3, day_gz='庚', name='初伏')

先计算某个节气,再向后加上一个日期间隔,该间隔依据60干支循环计算可得出。

Festival初始化freq支持字符串monthly/yearly

现状: 目前 SolarFestivalLunarFestivalfreq 属性类型为 int,通过 FreqConst 定义常量值。

last_day_of_month = SolarFestival(freq=FreqConst.MONTHLY, day=-1)  # FreqConst.MONTHLY = 1

改进1 :允许 freq 传入字符串 monthlyyearly ,这样不必导入 FreqConst 类,更符合使用语义。上述例子可改为:

last_day_of_month = SolarFestival(freq='monthly', day=-1)  # FreqConst.MONTHLY = 1

据此,freq参数类型声明修改为:

freq:Union[int, Literial['monthly', 'yearly']] = FreqConst.YEARLY

改进1.1 增加单字母 my 代表 monthlyyearly

注意: 该isssue仅修改 __init__ 函数的形参 freq 类型,并不改变 Festival._freq 的逻辑,其仍为 int 类型。

应用范围SolarFestivalLunarFestival

pylint代码静态检测结果

主题:根据 pylint 的检测结果优化相应代码。

执行命令 pylint borax ,结果如下:

************* Module borax.choices
borax\choices.py:76:56: E1101: Function 'fields' has no 'items' member (no-member)
borax\choices.py:80:21: E1101: Function 'fields' has no 'keys' member (no-member)
borax\choices.py:84:44: E1133: Non-iterable value cls.choices is used in an iterating context (not-an-iterable)
borax\choices.py:88:48: E1133: Non-iterable value cls.choices is used in an iterating context (not-an-iterable)
borax\choices.py:96:49: E1133: Non-iterable value cls.choices is used in an iterating context (not-an-iterable)
borax\choices.py:96:0: R1721: Unnecessary use of a comprehension (unnecessary-comprehension)
borax\choices.py:98:4: C0203: Metaclass method __contains__ should have 'cls' as first argument (bad-mcs-method-argument)
borax\choices.py:99:23: E1135: Value 'self.values' doesn't support membership test (unsupported-membership-test)
borax\choices.py:101:4: C0203: Metaclass method __iter__ should have 'cls' as first argument (bad-mcs-method-argument)
borax\choices.py:102:20: E1133: Non-iterable value self.choices is used in an iterating context (not-an-iterable)
borax\choices.py:105:4: C0203: Metaclass method __len__ should have 'cls' as first argument (bad-mcs-method-argument)
borax\choices.py:110:24: E1135: Value 'cls.display_lookup' doesn't support membership test (unsupported-membership-test)
borax\choices.py:113:15: E1101: Function 'display_lookup' has no 'get' member (no-member)
borax\choices.py:116:0: R0903: Too few public methods (0/2) (too-few-public-methods)
************* Module borax.constants
borax\constants.py:5:0: C0301: Line too long (123/120) (line-too-long)
borax\constants.py:8:0: R0903: Too few public methods (0/2) (too-few-public-methods)
************* Module borax.htmls
borax\htmls.py:51:4: R1705: Unnecessary "else" after "return" (no-else-return)
************* Module borax.numbers
borax\numbers.py:64:0: R0903: Too few public methods (1/2) (too-few-public-methods)
************* Module borax.utils
borax\utils.py:108:0: R1707: Disallow trailing comma tuple (trailing-comma-tuple)
borax\utils.py:8:4: R1705: Unnecessary "else" after "return" (no-else-return)
borax\utils.py:103:4: R1705: Unnecessary "elif" after "return" (no-else-return)
************* Module borax.calendars.festivals
borax\calendars\festivals.py:188:0: C0325: Unnecessary parens after 'not' keyword (superfluous-parens)
borax\calendars\festivals.py:25:0: W0613: Unused argument 'args' (unused-argument)
borax\calendars\festivals.py:37:15: E1101: Instance of 'DateSchema' has no 'year' member (no-member)
borax\calendars\festivals.py:46:65: W0212: Access to a protected member __key of a client class (protected-access)
borax\calendars\festivals.py:73:23: E1101: Instance of 'DateSchema' has no 'year' member (no-member)
borax\calendars\festivals.py:83:8: R1705: Unnecessary "else" after "return" (no-else-return)
borax\calendars\festivals.py:141:4: R0913: Too many arguments (6/5) (too-many-arguments)
borax\calendars\festivals.py:287:4: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
************* Module borax.calendars.lunardate
borax\calendars\lunardate.py:78:4: W0612: Unused variable 'leap_month' (unused-variable)
borax\calendars\lunardate.py:135:8: W0120: Else clause on loop without a break statement (useless-else-on-loop)
borax\calendars\lunardate.py:143:35: R1714: Consider merging these comparisons with "in" to 'month in (0, leap_month)' (consider-using-in)
borax\calendars\lunardate.py:168:8: R1705: Unnecessary "else" after "return" (no-else-return)
borax\calendars\lunardate.py:189:15: W0631: Using possibly undefined loop variable '_month' (undefined-loop-variable)
borax\calendars\lunardate.py:189:36: W0631: Using possibly undefined loop variable '_leap' (undefined-loop-variable)
borax\calendars\lunardate.py:199:28: W0631: Using possibly undefined loop variable 'idx' (undefined-loop-variable)
borax\calendars\lunardate.py:201:27: W0631: Using possibly undefined loop variable 'idx' (undefined-loop-variable)
borax\calendars\lunardate.py:212:16: R1705: Unnecessary "else" after "return" (no-else-return)
borax\calendars\lunardate.py:351:12: R1705: Unnecessary "else" after "return" (no-else-return)
borax\calendars\lunardate.py:364:0: R0902: Too many instance attributes (9/7) (too-many-instance-attributes)
borax\calendars\lunardate.py:456:12: R1705: Unnecessary "else" after "return" (no-else-return)
borax\calendars\lunardate.py:544:8: R1705: Unnecessary "elif" after "return" (no-else-return)
borax\calendars\lunardate.py:553:4: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
borax\calendars\lunardate.py:570:12: W0707: Consider explicitly re-raising using the 'from' keyword (raise-missing-from)
borax\calendars\lunardate.py:588:65: W0212: Access to a protected member __key of a client class (protected-access)
borax\calendars\lunardate.py:364:0: R0904: Too many public methods (30/20) (too-many-public-methods)
borax\calendars\lunardate.py:653:12: R1705: Unnecessary "else" after "return" (no-else-return)
borax\calendars\lunardate.py:660:4: R0201: Method could be a function (no-self-use)
borax\calendars\lunardate.py:663:4: R0201: Method could be a function (no-self-use)
borax\calendars\lunardate.py:667:8: R1705: Unnecessary "else" after "return" (no-else-return)
borax\calendars\lunardate.py:666:4: R0201: Method could be a function (no-self-use)
borax\calendars\lunardate.py:672:4: R0201: Method could be a function (no-self-use)
borax\calendars\lunardate.py:675:4: R0201: Method could be a function (no-self-use)
borax\calendars\lunardate.py:10:0: C0411: standard import "from typing import Optional, Iterator, Tuple" should be placed before "from .store import EncoderMixin, f_year, f_month, f_day, f_leap" (wrong-import-order)
************* Module borax.calendars.store
borax\calendars\store.py:19:12: R1705: Unnecessary "else" after "return" (no-else-return)
borax\calendars\store.py:27:8: R1705: Unnecessary "else" after "return" (no-else-return)
************* Module borax.counters.daily
borax\counters\daily.py:7:2: W0511: TODO Use Counter (fixme)
borax\counters\daily.py:26:8: R1705: Unnecessary "else" after "return" (no-else-return)
************* Module borax.counters.serial_pool
borax\counters\serial_pool.py:69:4: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
borax\counters\serial_pool.py:75:0: R0903: Too few public methods (0/2) (too-few-public-methods)
borax\counters\serial_pool.py:84:4: R0913: Too many arguments (6/5) (too-many-arguments)
************* Module borax.datasets.fetch
borax\datasets\fetch.py:11:0: R0903: Too few public methods (0/2) (too-few-public-methods)
borax\datasets\fetch.py:40:8: R1705: Unnecessary "else" after "return" (no-else-return)
borax\datasets\fetch.py:64:4: R1705: Unnecessary "else" after "return" (no-else-return)
borax\datasets\fetch.py:76:11: R1717: Consider using a dictionary comprehension (consider-using-dict-comprehension)
************* Module borax.datasets.join_
borax\datasets\join_.py:41:8: R1705: Unnecessary "elif" after "return" (no-else-return)
borax\datasets\join_.py:59:8: R1705: Unnecessary "elif" after "return" (no-else-return)
borax\datasets\join_.py:93:12: W0120: Else clause on loop without a break statement (useless-else-on-loop)
borax\datasets\join_.py:143:0: R0913: Too many arguments (6/5) (too-many-arguments)
************* Module borax.patterns.lazy
borax\patterns\lazy.py:15:11: W0212: Access to a protected member _wrapped of a client class (protected-access)
borax\patterns\lazy.py:16:12: W0212: Access to a protected member _setup of a client class (protected-access)
borax\patterns\lazy.py:17:20: W0212: Access to a protected member _wrapped of a client class (protected-access)
************* Module borax.patterns.proxy
borax\patterns\proxy.py:26:4: E0213: Method should have "self" as first argument (no-self-argument)
borax\patterns\proxy.py:46:15: R1725: Consider using Python 3 style super() without arguments (super-with-arguments)
************* Module borax.serialize.bjson
borax\serialize\bjson.py:11:0: R0903: Too few public methods (1/2) (too-few-public-methods)
************* Module borax.serialize.cjson
borax\serialize\cjson.py:22:0: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
borax\serialize\cjson.py:22:21: E1120: No value for argument 'cls' in function call (no-value-for-parameter)
borax\serialize\cjson.py:22:21: E1120: No value for argument 'type' in function call (no-value-for-parameter)
************* Module borax.structures.dictionary
borax\structures\dictionary.py:9:12: W0707: Consider explicitly re-raising using the 'from' keyword (raise-missing-from)
************* Module borax.structures.percentage
borax\structures\percentage.py:34:8: R1705: Unnecessary "else" after "return" (no-else-return)
************* Module borax.structures.tree
borax\structures\tree.py:32:0: R0914: Too many local variables (17/15) (too-many-locals)
borax\structures\tree.py:66:8: R1715: Consider using dict.get for getting values from a dict if a key is present or a default if not (consider-using-get)
************* Module borax.ui.widgets
borax\ui\widgets.py:6:0: R0901: Too many ancestors (8/7) (too-many-ancestors)
borax\ui\widgets.py:30:0: R0901: Too many ancestors (9/7) (too-many-ancestors)

------------------------------------------------------------------

Your code has been rated at 9.12/10 (previous run: 9.12/10, +0.00)




代码覆盖率分模块统计

主题:代码覆盖率按模块统计
类型 : 建议类
正文

由于 Borax 各个 Package 之间关联性不大,目前总的覆盖率也无法很好的反映更多的细节性问。建议参照 Status Checks 的内容进行具体的模块划分和统计。

LunarDate.cn_week属性计算错误

错误代码

    @property
    def cn_week(self) -> str:
        return TextUtils.DAYS_CN[self.weekday()]

导致星期一显示为星期日。

正确的代码

    @property
    def cn_week(self) -> str:
        return TextUtils.DAYS_CN[self.isoweekday()]

三伏天计算错误

2022年初伏计算错误,计算得出2022-07-26,实际是2022-07-16。但2021年计算正确。

cjson和JsonResponse整合问题

django.http.response.JsonResponse 中可以传入的参数是 cls 而不是 default,需要通过类中转。建议在 cjson 直接提供该类。

from borax.serialize import cjson

class BJSONEncoder:
    def default(self, o):
        return encoder(o)

rsp = JsonResponse(data, safe=False, cls=BJSONEncoder)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.