Best Python code snippet using hypothesis
game_server_banshu.spec
Source:game_server_banshu.spec  
1{2"money": {"description": "è´§å¸é
置表", "output": "../../doc/branches/banshu/game_server/data_money.config", "workbook": "../../doc/branches/banshu/RE0_item.xlsm", "sheet": "data_item", "label": 5, "begin": 6, "primkey": "type_id", "syntax": "off"}3, "section": {"description": "å
³å¡é
置表", "output": "../../doc/branches/banshu/game_server/data_section.config", "workbook": "../../doc/branches/banshu/RE0_section.xlsm", "sheet": "data_section", "label": 5, "begin": 6, "primkey": "section_id", "syntax": "off"}4, "chapter": {"description": "ç« èé
置表", "output": "../../doc/branches/banshu/game_server/data_chapter.config", "workbook": "../../doc/branches/banshu/RE0_chapter.xlsm", "sheet": "data_chapter", "label": 5, "begin": 6, "primkey": "chapter_id", "syntax": "off"}5, "monster": {"description": "æªç©é
置表", "output": "../../doc/branches/banshu/game_server/data_monster.config", "workbook": "../../doc/branches/banshu/RE0_monster.xlsm", "sheet": "data_monster", "label": 5, "begin": 6, "primkey": "type_id", "syntax": "off"}6, "drop": {"description": "æè½é
置表", "output": "../../doc/branches/banshu/game_server/data_drop.config", "workbook": "../../doc/branches/banshu/RE0_drop.xlsm", "sheet": "data_drop", "label": 5, "begin": 6, "primkey": "drop_id", "syntax": "off"}7, "role": {"description": "è§è²é
置表", "output": "../../doc/branches/banshu/game_server/data_ger.config", "workbook": "../../doc/branches/banshu/RE0_role.xlsm", "sheet": "data_role", "label": 5, "begin": 6, "primkey": "type_id", "syntax": "off"}8, "role_break": {"description": "è§è²çªç ´é
置表", "output": "../../doc/branches/banshu/game_server/data_ger_breakout.config", "workbook": "../../doc/branches/banshu/RE0_role_break.xlsm", "sheet": "data_role_break", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}9, "role_uplevel": {"description": "è§è²å¼ºåé
置表", "output": "../../doc/branches/banshu/game_server/data_ger_uplevel.config", "workbook": "../../doc/branches/banshu/RE0_role_uplevel.xlsm", "sheet": "data_role_uplevel", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}10, "equip_uplevel": {"description": "è£
å¤å¼ºåé
置表", "output": "../../doc/branches/banshu/game_server/data_equip_uplevel.config", "workbook": "../../doc/branches/banshu/RE0_equip_uplevel.xlsm", "sheet": "data_equip_uplevel", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}11, "equip_break": {"description": "è£
å¤çªç ´é
置表", "output": "../../doc/branches/banshu/game_server/data_equip_breakout.config", "workbook": "../../doc/branches/banshu/RE0_equip_break.xlsm", "sheet": "data_equip_break", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}12, "role_upskill": {"description": "è§è²æè½å¼ºåé
置表", "output": "../../doc/branches/banshu/game_server/data_ger_upskill.config", "workbook": "../../doc/branches/banshu/RE0_role_upskill.xlsm", "sheet": "data_role_upskill", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}13, "card": {"description": "强åå¡é
置表", "output": "../../doc/branches/banshu/game_server/data_card.config", "workbook": "../../doc/branches/banshu/RE0_qianghuacard.xlsm", "sheet": "data_qianghuacard", "label": 5, "begin": 6, "primkey": "type_id", "syntax": "off"}14, "lucky_bastard": {"description": "æ½å¡é
置表", "output": "../../doc/branches/banshu/game_server/data_box.config", "workbook": "../../doc/branches/banshu/RE0_lucky_bastard.xlsm", "sheet": "data_lucky_bastard", "label": 5, "begin": 6, "primkey": "pool_id", "syntax": "off"}15, "role_intimacy": {"description": "好æåº¦é
置表", "output": "../../doc/branches/banshu/game_server/data_intimacy.config", "workbook": "../../doc/branches/banshu/RE0_role_intimacy.xlsm", "sheet": "data_role_intimacy", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}16, "achieve_sub": {"description": "åæå°±é
置表", "output": "../../doc/branches/banshu/game_server/data_achieve_sub.config", "workbook": "../../doc/branches/banshu/RE0_achieve_sub.xlsm", "sheet": "data_achieve_sub", "label": 5, "begin": 6, "primkey": "sub_achieve_id", "syntax": "off"}17, "player_level": {"description": "ç©å®¶ç级é
置表", "output": "../../doc/branches/banshu/game_server/data_player_level.config", "workbook": "../../doc/branches/banshu/RE0_player_level.xlsm", "sheet": "data_player_level", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}18, "achieve": {"description": "æå°±ç³»ç»é
置表", "output": "../../doc/branches/banshu/game_server/data_achieve.config", "workbook": "../../doc/branches/banshu/RE0_achieve.xlsm", "sheet": "data_achieve", "label": 5, "begin": 6, "primkey": "achieve_id", "syntax": "off"}19, "mail_template": {"description": "é®ä»¶ç³»ç»é
置表", "output": "../../doc/branches/banshu/game_server/data_mail_template.config", "workbook": "../../doc/branches/banshu/RE0_mail_template.xlsm", "sheet": "data_mail_template", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}20, "intimacy_addattr": {"description": "好æåº¦å级å å±æ§é
置表", "output": "../../doc/branches/banshu/game_server/data_intimacy_addattr.config", "workbook": "../../doc/branches/banshu/RE0_intimacy_addattr.xlsm", "sheet": "data_intimacy_addattr", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}21, "sensitive_words": {"description": "ææè¯é
置表", "output": "../../doc/branches/banshu/game_server/data_sensitive_words.config", "workbook": "../../doc/branches/banshu/RE0_sensitive_words.xlsm", "sheet": "data_sensitive_words", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}22, "intimacy_uplevel": {"description": "好æåº¦å级é
置表", "output": "../../doc/branches/banshu/game_server/data_intimacy_uplevel.config", "workbook": "../../doc/branches/banshu/RE0_role_intimacy_uplevel.xlsm", "sheet": "data_role_intimacy_uplevel", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}23, "intimacy_gift": {"description": "好æåº¦ç¤¼ç©é
置表", "output": "../../doc/branches/banshu/game_server/data_intimacy_gift.config", "workbook": "../../doc/branches/banshu/RE0_role_intimacy_gift.xlsm", "sheet": "data_role_intimacy_gift", "label": 5, "begin": 6, "primkey": "type_id", "syntax": "off"}24, "scene": {"description": "åºæ¯é
置表", "output": "../../doc/branches/banshu/game_server/data_scene.config", "workbook": "../../doc/branches/banshu/RE0_scene.xlsm", "sheet": "data_scene", "label": 5, "begin": 6, "primkey": "type_id", "syntax": "off"}25, "collection": {"description": "cgå¨ç»é³ä¹èµæºé
置表", "output": "../../doc/branches/banshu/game_server/data_collection.config", "workbook": "../../doc/branches/banshu/RE0_collection.xlsm", "sheet": "data_collection", "label": 5, "begin": 6, "primkey": "type_id", "syntax": "off"}26, "shop": {"description": "ååºé
置表", "output": "../../doc/branches/banshu/game_server/data_shop.config", "workbook": "../../doc/branches/banshu/RE0_shop.xlsm", "sheet": "data_shop", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}27, "goods": {"description": "ååé
置表", "output": "../../doc/branches/banshu/game_server/data_goods.config", "workbook": "../../doc/branches/banshu/RE0_goods.xlsm", "sheet": "data_goods", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}28, "intimacy_section": {"description": "好æåº¦å§æ
é
置表", "output": "../../doc/branches/banshu/game_server/data_intimacy_section.config", "workbook": "../../doc/branches/banshu/RE0_role_intimacy_section.xlsm", "sheet": "data_role_intimacy_section", "label": 5, "begin": 6, "primkey": "section_id", "syntax": "off"}29, "inform": {"description": "å
¬åé
置表", "output": "../../doc/branches/banshu/game_server/data_inform.config", "workbook": "../../doc/branches/banshu/RE0_inform.xlsm", "sheet": "data_inform", "label": 5, "begin": 6, "primkey": "primkey", "syntax": "off"}30, "player_head": {"description": "ç©å®¶å¤´åé
置表", "output": "../../doc/branches/banshu/game_server/data_head.config", "workbook": "../../doc/branches/banshu/RE0_player_head.xlsm", "sheet": "data_player_head", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}31, "pay": {"description": "å
å¼é
置表", "output": "../../doc/branches/banshu/game_server/data_pay.config", "workbook": "../../doc/branches/banshu/RE0_pay.xlsm", "sheet": "data_pay", "label": 5, "begin": 6, "primkey": "pay_id", "syntax": "off"}32, "task": {"description": "ä»»å¡é
置表", "output": "../../doc/branches/banshu/game_server/data_task.config", "workbook": "../../doc/branches/banshu/RE0_task.xlsm", "sheet": "data_task", "label": 5, "begin": 6, "primkey": "task_id", "syntax": "off"}33, "boss": {"description": "ä¸çbossé
置表", "output": "../../doc/branches/banshu/game_server/data_boss.config", "workbook": "../../doc/branches/banshu/RE0_boss.xlsm", "sheet": "data_boss", "label": 5, "begin": 6, "primkey": "boss_id", "syntax": "off"}34, "robot": {"description": "æºå¨äººé
置表", "output": "../../doc/branches/banshu/game_server/data_robot.config", "workbook": "../../doc/branches/banshu/RE0_robot.xlsm", "sheet": "data_robot", "label": 5, "begin": 6, "primkey": "role_id", "syntax": "off"}35, "train": {"description": "ç¹è®é
置表", "output": "../../doc/branches/banshu/game_server/data_train.config", "workbook": "../../doc/branches/banshu/RE0_train.xlsm", "sheet": "data_train", "label": 5, "begin": 6, "primkey": "train_id", "syntax": "off"}36, "sign": {"description": "ç¾å°é
置表", "output": "../../doc/branches/banshu/game_server/data_sign.config", "workbook": "../../doc/branches/banshu/RE0_sign.xlsm", "sheet": "data_sign", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}37, "skill": {"description": "æè½é
置表", "output": "../../doc/branches/banshu/game_server/data_skill.config", "workbook": "../../doc/branches/banshu/RE0_skill.xlsm", "sheet": "data_skill", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}38, "card_pool": {"description": "æ½å¡äº§åºé
置表", "output": "../../doc/branches/banshu/game_server/data_card_pool.config", "workbook": "../../doc/branches/banshu/RE0_card_pool.xlsm", "sheet": "data_card_pool", "label": 5, "begin": 6, "primkey": "draw_id", "syntax": "off"}39, "clientconfig": {"description": "客æ·ç«¯æé¡¹é
置表", "output": "../../doc/branches/banshu/game_server/data_clientconfig.config", "workbook": "../../doc/branches/banshu/RE0_clientconfig.xlsm", "sheet": "data_clientconfig", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}40, "buy_gold": {"description": "è´ä¹°éå¸é
置表", "output": "../../doc/branches/banshu/game_server/data_buy_gold.config", "workbook": "../../doc/branches/banshu/RE0_buy_gold.xlsm", "sheet": "data_buy_gold", "label": 5, "begin": 6, "primkey": "count", "syntax": "off"},41"rehearse": {"description": "æ¼ç»æé
置表", "output": "../../doc/branches/banshu/game_server/data_drillroom.config", "workbook": "../../doc/branches/banshu/RE0_rehearse.xlsm", "sheet": "data_rehearse", "label": 5, "begin": 6, "primkey": "npc_id", "syntax": "off"},42"rehearse_time": {"description": "æ¼ç»æé¶æ®µé
置表", "output": "../../doc/branches/banshu/game_server/data_drillroom_period.config", "workbook": "../../doc/branches/banshu/RE0_rehearse_time.xlsm", "sheet": "data_rehearse_time", "label": 5, "begin": 6, "primkey": "time_id", "syntax": "off"}43, "global": {"description": "å
¨å±åéé
置表", "output": "../../doc/branches/banshu/game_server/data_global.config", "workbook": "../../doc/branches/banshu/RE0_global.xlsm", "sheet": "data_global", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}44, "whitelist": {"description": "ç©å®¶ç½ååé
置表", "output": "../../doc/branches/banshu/game_server/data_whitelist.config", "workbook": "../../doc/branches/banshu/RE0_whitelist.xlsm", "sheet": "data_whitelist", "label": 5, "begin": 6, "primkey": "id", "syntax": "off"}...data.py
Source:data.py  
...33_ft_Classification = feature_test("Classification")34#manually encode greedy ID tree for classifying trees35def get_tree_tree():36    tree = IDTNode(_ft_tt)._ssc(tree_classifiers[0], tree_data)37    branches = tree.get_branches()38    branches["Glossy"].set_node_classification("Oak")39    branches["Smooth"].set_node_classification("Maple")40    subnode = branches["Furrowed"]._ssc(tree_classifiers[3], tree_data_furrowed)41    subbranches = subnode.get_branches()42    subbranches["Yes"].set_node_classification("Maple")43    subbranches["No"].set_node_classification("Oak")44    return tree45def get_tree_tree_impossible():46    tree = IDTNode(_ft_tt)._ssc(tree_classifiers[0], tree_data)47    branches = tree.get_branches()48    branches["Glossy"].set_node_classification("Oak")49    branches["Smooth"].set_node_classification("Maple")50    subnode = branches["Furrowed"]._ssc(tree_classifiers[2], tree_data_furrowed)51    subbranches = subnode.get_branches()52    subbranches["Rounded"].set_node_classification("Oak")53    return tree54tree_classifiers_reverse = [\55    feature_test("has_leaves"),56    feature_test("leaf_shape"),57    feature_test("orange_foliage"),58    feature_test("tree_type"),59]60tree_test_point = {"name":"Tree7", "has_leaves":"Yes", "orange_foliage":"Yes", "leaf_shape":"Rounded", "bark_texture":"Furrowed"}61# Test what happens if it's not possible to complete the tree62tree_classifiers_impossible = [\63    feature_test("bark_texture"),64    feature_test("has_leaves"),65    feature_test("leaf_shape"),66]67# 2012 Q2: Angel or Not Angel?68angel_data = [\69    {"name":"Statue1", "Classification":"Angel", "Height":7, "Shape":"Human", "Material":"Stone"},70    {"name":"Statue2", "Classification":"Angel", "Height":2.5, "Shape":"Human", "Material":"Stone"},71    {"name":"Statue3", "Classification":"Not Angel", "Height":7, "Shape":"Human", "Material":"Copper"},72    {"name":"Statue4", "Classification":"Not Angel", "Height":3, "Shape":"Animal", "Material":"Copper"},73    {"name":"Statue5", "Classification":"Not Angel", "Height":8, "Shape":"Animal", "Material":"Stone"},74    {"name":"Statue6", "Classification":"Angel", "Height":305, "Shape":"Human", "Material":"Copper"},75]76angel_classifiers = [\77    feature_test("Shape"),78    threshold_test("Height", 7),79    feature_test("Material"),80]81_branches_yesno = ["No","Yes"]82# manually encode greedy ID tree83def get_angel_tree():84    tree = IDTNode(_ft_Classification)._ssc(angel_classifiers[0], angel_data)85    branches = tree.get_branches()86    branches["Animal"].set_node_classification("Not Angel")87    branches = branches["Human"].set_classifier_and_expand(angel_classifiers[2], ["Stone","Copper"]).get_branches()88    branches["Stone"].set_node_classification("Angel")89    branches = branches["Copper"].set_classifier_and_expand(angel_classifiers[1], _branches_yesno).get_branches()90    branches["No"].set_node_classification("Not Angel")91    branches["Yes"].set_node_classification("Angel")92    return tree93# 2013 Q2: Numeric ID tree94numeric_pre_data = {\95    "A": [(0.5, 1.5), (1.5, 0.5), (1.5, 1.5), (2.5, 0.5), (2.5, 2.5), (3.5, 0.5)],96    "B": [(0.5, 3.5), (2.5, 1.5), (3.5, 2.5)]97}98numeric_data0 = [[{"name":str((x,y)), "class":A_or_B, "X":x, "Y":y}99                  for (x,y) in points]100                 for (A_or_B, points) in [("A", numeric_pre_data["A"]), ("B", numeric_pre_data["B"])]]101                 # Don't dare try to use .items() because the order is not guaranteed102numeric_data = numeric_data0[0] + numeric_data0[1]103numeric_classifiers = [\104    threshold_test("X", 1),105    threshold_test("X", 2),106    threshold_test("X", 3),107    threshold_test("Y", 1),108    threshold_test("Y", 2),109    threshold_test("Y", 3),110]111# manually encode greedy ID tree112def get_numeric_tree():113    tree = IDTNode(_ft_class)._ssc(numeric_classifiers[3], numeric_data)114    branches = tree.get_branches()115    branches["No"].set_node_classification("A")116    branches = branches["Yes"].set_classifier_and_expand(numeric_classifiers[2],_branches_yesno).get_branches()117    branches["Yes"].set_node_classification("B")118    branches = branches["No"].set_classifier_and_expand(numeric_classifiers[5],_branches_yesno).get_branches()119    branches["Yes"].set_node_classification("B")120    branches = branches["No"].set_classifier_and_expand(numeric_classifiers[1],_branches_yesno).get_branches()121    branches["No"].set_node_classification("A")122    branches = branches["Yes"].set_classifier_and_expand(numeric_classifiers[4],_branches_yesno).get_branches()123    branches["No"].set_node_classification("B")124    branches["Yes"].set_node_classification("A")125    return tree126# toy data for ID trees127toy_data_1 = [\128    {"name":"toypoint1", "class":1, "attr1":2, "attr2":4, "attr3":6},129    {"name":"toypoint2", "class":-1, "attr1":3, "attr2":5, "attr3":7}130]131toy_classifiers_1 = [\132    feature_test("attr2"),133    feature_test("attr1"),134    feature_test("attr3"),135]136toy_data_2 = [\137    {"name":"p1", "class":"A", "flavor":"vanilla"},138    {"name":"p2", "class":"B", "flavor":"vanilla"},139    {"name":"p3", "class":"C", "flavor":"vanilla"},140    {"name":"p4", "class":"D", "flavor":"chocolate"},141    {"name":"p5", "class":"A", "flavor":"chocolate"},142    {"name":"p6", "class":"B", "flavor":"chocolate"},143]144toy_classifiers_2 = [feature_test("flavor")]145# binary XOR data and trees146binary_pre_data = [\147    (1,0,0,0,0),148    (2,0,0,0,1),149    (3,1,0,1,0),150    (4,1,0,1,1),151    (5,1,1,0,1),152    (6,1,1,0,1),153    (7,0,1,1,0),154]155binary_data = [{"name":"point"+str(i), "Classification":s, "A":a, "B":b, "C":c}156               for (i,s,a,b,c) in binary_pre_data]157binary_classifiers = [feature_test("A"), feature_test("B"), feature_test("C")]158(bcA, bcB, bcC) = binary_classifiers159_branches_01=[0,1]160def get_binary_tree_1():161    tree = IDTNode(_ft_Classification)._ssc(bcB, binary_data)162    branches = tree.get_branches()163    branches[1].set_node_classification(1)164    branches = branches[0].set_classifier_and_expand(bcA,_branches_01).get_branches()165    branches[0].set_node_classification(0)166    branches[1].set_node_classification(1)167    return tree168def get_binary_tree_2():169    tree = IDTNode(_ft_Classification)._ssc(bcA, binary_data)170    branches = tree.get_branches()171    branches0 = branches[0].set_classifier_and_expand(bcB,_branches_01).get_branches()172    branches1 = branches[1].set_classifier_and_expand(bcB,_branches_01).get_branches()173    branches0[0].set_node_classification(0)174    branches0[1].set_node_classification(1)175    branches1[0].set_node_classification(1)176    branches1[1].set_node_classification(0)177    return tree178def get_binary_tree_3():179    tree = IDTNode(_ft_Classification)._ssc(bcC, binary_data)180    branches = tree.get_branches()181    branches0 = branches[0].set_classifier_and_expand(bcA,_branches_01).get_branches()182    branches1 = branches[1].set_classifier_and_expand(bcA,_branches_01).get_branches()183    branches0[1].set_node_classification(0)184    branches00 = branches0[0].set_classifier_and_expand(bcB,_branches_01).get_branches()185    branches00[0].set_node_classification(0)186    branches00[1].set_node_classification(1)187    branches1[1].set_node_classification(1)188    branches10 = branches1[0].set_classifier_and_expand(bcB,_branches_01).get_branches()189    branches10[0].set_node_classification(0)190    branches10[1].set_node_classification(1)191    return tree192binary_tree_1 = get_binary_tree_1()193binary_tree_2 = get_binary_tree_2()194binary_tree_3 = get_binary_tree_3()195################################################################################196############################# k-NEAREST NEIGHBORS ##############################197################################################################################198# 2014 Q2: Oak or Maple?199knn_tree_data = [\200    Point((10,5), "Oak"),201    Point((20,15), "Oak"),202    Point((20,40), "Oak"), #outlier...data.js
Source:data.js  
1const servicesTable = [{2    "id": 51, // key : value3    "service": "Tres-Zap",4    "trademark": "Skynoodle",5    "branches": 63,6    "country": "Indonesia",7    "status": false8  }, {9    "id": 41,10    "service": "Duobam",11    "trademark": "Jabbersphere",12    "branches": 88,13    "country": "Russia",14    "status": true15  }, {16    "id": 27,17    "service": "Y-find",18    "trademark": "Jamia",19    "branches": 12,20    "country": "Luxembourg",21    "status": false22  }, {23    "id": 74,24    "service": "Tin",25    "trademark": "Youopia",26    "branches": 12,27    "country": "Sweden",28    "status": false29  }, {30    "id": 59,31    "service": "Tampflex",32    "trademark": "Flashdog",33    "branches": 23,34    "country": "China",35    "status": false36  }, {37    "id": 93,38    "service": "Fintone",39    "trademark": "Youspan",40    "branches": 43,41    "country": "Indonesia",42    "status": false43  }, {44    "id": 47,45    "service": "Temp",46    "trademark": "Skipstorm",47    "branches": 24,48    "country": "Palestinian Territory",49    "status": true50  }, {51    "id": 26,52    "service": "Sonsing",53    "trademark": "Flashset",54    "branches": 42,55    "country": "China",56    "status": false57  }, {58    "id": 98,59    "service": "Biodex",60    "trademark": "Vinder",61    "branches": 97,62    "country": "Philippines",63    "status": true64  }, {65    "id": 17,66    "service": "Pannier",67    "trademark": "Topicblab",68    "branches": 86,69    "country": "China",70    "status": true71  }, {72    "id": 95,73    "service": "Overhold",74    "trademark": "Realcube",75    "branches": 15,76    "country": "Russia",77    "status": true78  }, {79    "id": 5,80    "service": "Fixflex",81    "trademark": "Twimbo",82    "branches": 52,83    "country": "Brazil",84    "status": true85  }, {86    "id": 62,87    "service": "Alpha",88    "trademark": "Realbuzz",89    "branches": 23,90    "country": "Czech Republic",91    "status": true92  }, {93    "id": 33,94    "service": "Y-Solowarm",95    "trademark": "Voonder",96    "branches": 19,97    "country": "Colombia",98    "status": false99  }, {100    "id": 66,101    "service": "Aerified",102    "trademark": "Blogspan",103    "branches": 75,104    "country": "Portugal",105    "status": true106  }, {107    "id": 62,108    "service": "Veribet",109    "trademark": "Mynte",110    "branches": 11,111    "country": "Bulgaria",112    "status": false113  }, {114    "id": 15,115    "service": "Fix San",116    "trademark": "Minyx",117    "branches": 12,118    "country": "Poland",119    "status": false120  }, {121    "id": 42,122    "service": "Sub-Ex",123    "trademark": "Devify",124    "branches": 8,125    "country": "United States",126    "status": true127  }, {128    "id": 21,129    "service": "Voyatouch",130    "trademark": "Twitterbeat",131    "branches": 80,132    "country": "Belarus",133    "status": true134  }, {135    "id": 33,136    "service": "Voltsillam",137    "trademark": "Skyba",138    "branches": 6,139    "country": "France",140    "status": false141  }, {142    "id": 25,143    "service": "Voyatouch",144    "trademark": "Wordpedia",145    "branches": 62,146    "country": "China",147    "status": false148  }, {149    "id": 22,150    "service": "Andalax",151    "trademark": "Kayveo",152    "branches": 35,153    "country": "China",154    "status": false155  }, {156    "id": 3,157    "service": "Cookley",158    "trademark": "Browsecat",159    "branches": 39,160    "country": "China",161    "status": true162  }, {163    "id": 48,164    "service": "Mat Lam Tam",165    "trademark": "Vitz",166    "branches": 69,167    "country": "Ukraine",168    "status": true169  }, {170    "id": 52,171    "service": "Greenlam",172    "trademark": "Demivee",173    "branches": 25,174    "country": "United States",175    "status": false176  }, {177    "id": 97,178    "service": "Konklux",179    "trademark": "Mymm",180    "branches": 46,181    "country": "Philippines",182    "status": false183  }, {184    "id": 41,185    "service": "Matsoft",186    "trademark": "Plajo",187    "branches": 12,188    "country": "Georgia",189    "status": false190  }, {191    "id": 26,192    "service": "Toughjoyfax",193    "trademark": "Meetz",194    "branches": 100,195    "country": "Poland",196    "status": true197  }, {198    "id": 85,199    "service": "Fixflex",200    "trademark": "Divanoodle",201    "branches": 34,202    "country": "China",203    "status": false204  }, {205    "id": 82,206    "service": "Konklab",207    "trademark": "Skimia",208    "branches": 48,209    "country": "Indonesia",210    "status": false211  }, {212    "id": 14,213    "service": "Holdlamis",214    "trademark": "Aimbu",215    "branches": 63,216    "country": "Japan",217    "status": true218  }, {219    "id": 81,220    "service": "Andalax",221    "trademark": "Yakitri",222    "branches": 89,223    "country": "Indonesia",224    "status": false225  }, {226    "id": 68,227    "service": "Tresom",228    "trademark": "Zooveo",229    "branches": 19,230    "country": "Indonesia",231    "status": false232  }, {233    "id": 13,234    "service": "Sub-Ex",235    "trademark": "Zoomlounge",236    "branches": 45,237    "country": "France",238    "status": false239  }, {240    "id": 10,241    "service": "Flowdesk",242    "trademark": "Devpoint",243    "branches": 57,244    "country": "Mexico",245    "status": false246  }, {247    "id": 4,248    "service": "Biodex",249    "trademark": "Topiclounge",250    "branches": 80,251    "country": "Indonesia",252    "status": false253  }, {254    "id": 90,255    "service": "Flexidy",256    "trademark": "Eidel",257    "branches": 14,258    "country": "Sweden",259    "status": true260  }, {261    "id": 60,262    "service": "Toughjoyfax",263    "trademark": "Wikizz",264    "branches": 26,265    "country": "China",266    "status": true267  }, {268    "id": 12,269    "service": "Fixflex",270    "trademark": "Miboo",271    "branches": 24,272    "country": "Thailand",273    "status": true274  }, {275    "id": 93,276    "service": "Y-find",277    "trademark": "Browsebug",278    "branches": 17,279    "country": "Canada",280    "status": true281  }, {282    "id": 37,283    "service": "Zaam-Dox",284    "trademark": "Jaxbean",285    "branches": 28,286    "country": "Serbia",287    "status": true288  }, {289    "id": 79,290    "service": "Flexidy",291    "trademark": "Oba",292    "branches": 61,293    "country": "Iran",294    "status": true295  }, {296    "id": 56,297    "service": "Sub-Ex",298    "trademark": "Mudo",299    "branches": 67,300    "country": "Bangladesh",301    "status": false302  }, {303    "id": 8,304    "service": "Quo Lux",305    "trademark": "Meevee",306    "branches": 99,307    "country": "China",308    "status": false309  }, {310    "id": 20,311    "service": "Vagram",312    "trademark": "Flashpoint",313    "branches": 67,314    "country": "Poland",315    "status": true316  }, {317    "id": 51,318    "service": "Subin",319    "trademark": "Dabjam",320    "branches": 72,321    "country": "Colombia",322    "status": true323  }, {324    "id": 69,325    "service": "Temp",326    "trademark": "Topiczoom",327    "branches": 6,328    "country": "Palestinian Territory",329    "status": true330  }, {331    "id": 57,332    "service": "Flowdesk",333    "trademark": "Flipopia",334    "branches": 28,335    "country": "Russia",336    "status": true337  }, {338    "id": 28,339    "service": "Tres-Zap",340    "trademark": "Kwinu",341    "branches": 15,342    "country": "Indonesia",343    "status": true344  }, {345    "id": 35,346    "service": "Wrapsafe",347    "trademark": "Roomm",348    "branches": 55,349    "country": "Indonesia",350    "status": false351  }, ]...items-array.service.ts
Source:items-array.service.ts  
1import {Injectable} from '@angular/core';2import {Branch, CommonCategory, Contacts, Item, ItemsService, MenuCategory, SoldItem} from './items.service';3import {BehaviorSubject, Observable} from 'rxjs';4import {environment} from './environments/environment';5import {map} from 'rxjs/operators';6import {HttpClient} from '@angular/common/http';7@Injectable({8  providedIn: 'root'9})10export class ItemsArrayService implements ItemsService {11  contacts: Contacts;12  branches$ = new BehaviorSubject<Branch[]>([]);13  items$ = new BehaviorSubject<MenuCategory[]>([]);14  items;15  constructor(private http: HttpClient) {16    this.GetContacts().subscribe(17      res => {18        this.contacts = res;19      }20    );21    this.http.get<Branch[]>(`${environment.apiUrl}/api/branches`).subscribe(22      res => {23        this.branches$.next(Object.assign([], res));24      }25    );26    this.http.get<[]>(`${environment.apiUrl}/api/items`).subscribe(27      res => {28        this.items$.next(Object.assign([], res));29      }30    );31  }32  AddItem(item: Item, categoryName: string): Observable<Item> {33    this.items = this.items$.value;34    const category = this.items.find(c => c.categoryName === categoryName);35    category.products.push(item);36    return this.http.put<Item>(`${environment.apiUrl}/api/items/${category.id}`, category);37  }38  DeleteItem(item: Item): Observable<boolean> {39    this.items = this.items$.value;40    const category: MenuCategory = this.items.find(c =>  item.menuCategory === c.categoryName);41    const itIndx = category.products.findIndex(i => (i.prodId) === (item.prodId));42    category.products.splice(itIndx, 1);43    return this.http.put<MenuCategory>(`${environment.apiUrl}/api/items/${category.id}`, category).pipe(map(44      res => {45        if (res) {46          this.items$.next(this.items);47          return true;48        }49      }50    ));51  }52  EditItem(item: Item): Observable<Item> {53    this.items = this.items$.value;54    const category: MenuCategory = this.items.find(c =>  item.menuCategory === c.categoryName);55    const idx = category.products.findIndex(i => i.prodId === item.prodId);56    category.products[idx] = item;57    return this.http.put<MenuCategory>(`${environment.apiUrl}/api/items/${category.id}`, category).pipe(map(58      res => {59        if (res) {60          this.items$.next(this.items);61          return item;62        }63      }64    ));65  }66  GetContacts(): Observable<Contacts> {67    return this.http.get<Contacts>(`${environment.apiUrl}/api/contacts/0`);68  }69  EditContacts(instagram, facebook, email, phone1, phone2, phone3, address): Observable<Contacts> {70    return this.http.patch<Contacts>(`${environment.apiUrl}/api/contacts/0`, {instagram, facebook, email, phone1, phone2, phone3, address}).pipe(map( res => {71        if (res) {72          this.contacts.instagram = res.instagram;73          this.contacts.facebook = res.facebook;74          this.contacts.email = res.email;75          this.contacts.phone1 = res.phone1;76          this.contacts.phone2 = res.phone2;77          this.contacts.phone3 = res.phone3;78          this.contacts.address = res.address;79        }80        return res;81      }, err => {82        console.error('error from server', err);83      }84    ));85  }86  DeleteBranch(branch): Observable<boolean> {87    return this.http.delete<boolean>(`${environment.apiUrl}/api/branches/${branch.id}`).pipe(map(88      res => {89        const branches = this.branches$.value;90        const brIndx = branches.findIndex(b => b.id === branch.id);91        branches.splice(brIndx, 1);92        this.branches$.next(branches);93        return true;94      }, err => {95        return false;96      }97    ));98  }99  GetBranches(): Observable<Branch[]> {100    return this.branches$.asObservable();101  }102  EditBranch(branch): Observable<Branch> {103    return this.http.patch<Branch>(`${environment.apiUrl}/api/branches/${branch.id}`, {address: branch.address, desc: branch.desc, photo: branch.photo}).pipe(map(104      res => {105        const branches = this.branches$.value;106        const brIndx = branches.findIndex(b => b.id === branch.id);107        branches[brIndx] = res;108        this.branches$.next(branches);109        return branch;110      }111    ));112  }113  ChangeBranchStatus(branch: Branch, newStatus: boolean): Observable<boolean> {114    return this.http.patch<boolean>(`${environment.apiUrl}/api/branches/${branch.id}`, {popular: newStatus}).pipe(map(115      res => {116        const branches = this.branches$.value;117        const brIndx = branches.findIndex(b => b.id === branch.id);118        if (!branch.popular) {119          branch.popular = true;120          this.branches$.next(branches);121          return true;122        }123        branches[brIndx].popular = !branches[brIndx].popular;124        this.branches$.next(branches);125        return true;126      }127    ));128  }129  AddNewBranch(newBranch: Branch): Observable<boolean> {130    return this.http.post<Branch>(`${environment.apiUrl}/api/branches`, newBranch).pipe(map(131      res => {132        const branches = this.branches$.value;133        branches.push(res);134        this.branches$.next(branches);135        return true;136      }, err => {137        return err;138      }139  ));140  }141  GetCommonCategories(): Observable<CommonCategory[]> {142    return this.http.get<CommonCategory[]>(`${environment.apiUrl}/api/common_categories`);143  }144  GetAllTheItems(): Observable<MenuCategory[]> {145    return this.items$.asObservable();146  }147  getBranchById(id: number): Observable<Branch> {148    return this.http.get<Branch>(`${environment.apiUrl}/api/branches/${id}`);149  }150  GetPromoItems(): Observable<Item[]> {151    return this.http.get<Item[]>(`${environment.apiUrl}/api/promoItems`);152  }153  GetNewItems(): Observable<Item[]> {154    return this.http.get<Item[]>(`${environment.apiUrl}/api/newItems`);155  }156  SoldTheItem(sItem: SoldItem): Observable<boolean> {157    return this.http.post<boolean>(`${environment.apiUrl}/api/sold`, sItem);158  }...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!!
