Exemplo n.º 1
0
def test_target_get():
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    import os
    path = "../datasource/广告投放效果2.xls"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='广告投放效果', path=path)
    # s1 = "查询最大APP下载量"
    # s1 = Sentence(s1, table)
    # print(s1.nodes)
    # from ch2sql.parser import Parser
    # s1 = Parser(s1)
    # res = s1.select_parser()
    # print(res)  # [MAX(APP下载量)] 结果正确

    # s2 = "查询最大APP下载量和平均APP下载量"
    # s2 = Sentence(s2, table)
    # print(s2.nodes)
    # from ch2sql.parser import Parser
    # s2 = Parser(s2)
    # res = s2.select_parser()
    # print(res)  # [AVG(APP下载量), MAX(APP下载量)] 结果正确

    s3 = "查询今年每个月的APP下载量总量和平均APP激活量"
    s3 = Sentence(s3, table)
    print(s3.nodes)
    from ch2sql.parser import Parser
    s2 = Parser(s3)
    res = s2.select_parser()
    print(res)  # [AVG(APP下载量), MAX(APP下载量)] 结果正确
Exemplo n.º 2
0
def test_total_04():
    """
    {
    "select": [
        "订单号"
    ],
    "condition_and": [
        "客户名称 = 京东商城"
    ],
    "condition_or": [],
    "order_by_desc": [],
    "group_by": [],
    "having": [],
    "result_limit": null,
    "date_from": null,
    "data_to": null
    }
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "查询京东商城的订单编号"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())
Exemplo n.º 3
0
def test_condition_parser1():
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "查询最高平均不含税金额大于1000的数据"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    print(s1.select_parser())
    s1.condition_parser()
Exemplo n.º 4
0
def test_total_01():
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "京东商城税费小于10的单据日期"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    print(s1.select_targets)
    print(s1.conditions)
Exemplo n.º 5
0
def test_total_17():
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "订单编号大于50的客户名称"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())
Exemplo n.º 6
0
def test_condition_parser3():
    """
    带有逻辑连接符号的纯值条件节点解析
    eg. '销售部或者电子商务部'
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "销售部或者电子商务部的情况"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.condition_parser()
Exemplo n.º 7
0
def test_condition_parser2():
    """
    测试值条件节点的处理情况
    eg: "京东商城的平均单价"
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "京东商城的平均单价"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    print(s1.select_parser())
    s1.condition_parser()
Exemplo n.º 8
0
def test_condition_parser4():
    """
    对包含group by top修饰的属性名条件节点解析
    eg. "各部门的平均税费"
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "各部门名称的平均税款"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    print(s1.select_targets)
    s1.condition_parser()
Exemplo n.º 9
0
def test_total_08():
    """
     在这种情况下会出现混乱
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "各业务员的总订单金额"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())
Exemplo n.º 10
0
def test_condition_parser6():
    """
    top
    eg. "利润top10的部门名称"
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "不同部门名称的利润均值"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    print(s1.select_targets)
    print(s1.conditions)
Exemplo n.º 11
0
def test_total_20():
    """
    {
    "select": [
        "利润"
    ],
    "condition_and": [
        "客户名称 = 淘宝网"
    ],
    "condition_or": [],
    "order_by_desc": [],
    "group_by": [],
    "having": [],
    "result_limit": null,
    "date_from": "2014-12-01",
    "date_to": "2014-12-31"
     }
    :return:
    """

    s1 = "2014年12月淘宝网的利润"
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    print(s1.parser_tree)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())
Exemplo n.º 12
0
def test_total_19():
    """
    {
    "select": [
        "COUNT(订单号)",
        "部门名称"
    ],
    "condition_and": [],
    "condition_or": [],
    "order_by_desc": [],
    "group_by": [
        "部门名称"
    ],
    "having": [],
    "result_limit": null,
    "date_from": "None",
    "date_to": "None"
   }
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "各部门名称的订单号总数"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    print(s1.parser_tree)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())