{# templates/wm_messages.jinja seekerUp模板 #} {# 计算数字的整数部分 #} {% macro count_round(value) %} {% set value = value | int %} {{ (value / 10) | round(0) | int * 10 }} {% endmacro %} {% macro approx_fraction(p) -%} {%- set p = 99 if p |int >= 100 else p -%} {%- if p >= 50 -%} 百分之{{ ['','一','二','三','四','五','六','七','八','九'][p//10] }}{{ '十' if p >= 10 else '' }}{{ ['','一','二','三','四','五','六','七','八','九'][p%10] if p%10 else '' }} {%- elif p >= 40 -%}一半 {%- else -%}三分之一 {%- endif -%} {%- endmacro %} {# ---------------------内部随机用的数组 --------------------- #} {% set greeting = ["嗨", "哈喽"] %} {% set assistant1 = ["小优来啦", "你的洗护小管家来啦", "你的洗护小助手来啦", "你的洗护小精灵来啦", "你的洗护小管家上线啦", "你的洗护小助手上线啦", "你的洗护小精灵上线啦", "小优前来报到", "洗护小管家前来报道", "洗护小助手前来报道", "洗护小精灵前来报到"] %} {% set assistant2 = ["干衣推荐来啦", "干衣小贴士来啦", "又要烘干衣服啦", "又来烘干衣服啦", "干衣时间到啦"] %} {% set user1 = [ "位用户", "位邻居", "位朋友", "户家庭", "个小伙伴"] %} {% set user2 = ["用户", "小伙伴", "邻居"] %} {% set program_name_map={ "56":"智慧烘", "15":"速烘", "17":"大物", "3":"羽绒", "52":"冲锋衣", "6":"衬衣", "7":"童装", "14":"内衣", "118":"除菌螨", "30":"除毛烘", "131":"夏凉被", "58":"浴巾", "1":"棉麻", "45":"云程序", "43":"定时烘", "34":"静筒烘", "22":"丝绸", "10":"羊毛" } %} {# 烘干参数对应关系 #} {%macro commands_params(changed_params) -%} {# {{ [ "干燥度:{}".format(changed_params.DryLevel) if changed_params.DryLevel and changed_params.DryLevel != "0" else "", "温度:{}".format(changed_params.DryTemp) if changed_params.DryTemp and changed_params.DryTemp != "0" else "", "风力{}挡".format(changed_params.FanLevel) if changed_params.FanLevel and changed_params.FanLevel != "0" else "" ] | reject("equalto", "") | join(",") }} #} {# 干燥度枚举映射 #} {% set dry_level_map = { "1": "即熨", "2": "即穿", "3": "储藏", "4": "特干" } %} {# 温度枚举映射 #} {% set dry_temp_map = { "1": "冷风", "2": "低温", "3": "中温", "4": "高温" } %} {# 烘干参数对应关系 #} {% macro commands_params(changed_params) -%} {{ [ "干燥度:{}".format(dry_level_map.get(changed_params.DryLevel)) if changed_params.DryLevel and changed_params.DryLevel != "0" else "", "温度:{}".format(dry_temp_map.get(changed_params.DryTemp)) if changed_params.DryTemp and changed_params.DryTemp != "0" else "", "风力{}挡".format(changed_params.FanLevel) if changed_params.FanLevel and changed_params.FanLevel != "0" else "" ] | reject("equalto", "") | join(",") }} {%- endmacro %} {# --------------------- 人气/定制简短模板函数 --------------------- #} {% macro brief_popularity_message(city, program_id, period, season ,card_type, changed_params,recommend_type) -%} {% set prefix_message %} {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {% if program_name %} {% if rerank_reason |upper == "PIN_CONSECUTIVE" %} {%set commands_text = commands_params(changed_params)%} {{[ "{0}好呀,小优发现你最近几次干衣都喜欢用{1}程序,{2}给你准备好了。".format(period, program_name, commands_text~"," if commands_text else "" ), "{0},发现你最近几次干衣都使用{1},{2}给你准备好了。".format(assistant1 | random, program_name, commands_text~"," if commands_text else "" ), "{0},为你推荐最近几次常用的{1}程序,{2}赶快启动吧!".format(assistant2 | random, program_name, commands_text~"," if commands_text else "" ), "{0},最懂你的小优来啦,你最近几次干衣都使用了{1}程序,{2}这次还这么用吧。".format(greeting |random, program_name, commands_text~"," if commands_text else "" ), "又能帮你烘干衣服了,小优很开心哦。前几次干衣你都使用{0}程序,我猜你这次还想用它。".format( program_name ) ] | random }} {% elif rerank_reason |upper == "PIN_WEEKLY" %} {%set feature_week_name="每周这个时间都喜欢用"%} {%set commands_text = commands_params(changed_params)%} {{[ "{0}好呀,小优发现你{1}{2}程序,{3}给你准备好了。".format( period, feature_week_name, program_name, commands_text~"," if commands_text else "" ), "{0}好呀,小优准备了你{1}的{2}程序。{3}快来启动吧。".format( period, feature_week_name, program_name, commands_text~"," if commands_text else "" ), "{0},{1},推荐你{2}的{3}程序。{4}".format( greeting |random, assistant1 | random, feature_week_name, program_name, commands_text~"。" if commands_text else "" ), "{0},你{1}的{2}程序,{3}给你准备好了。".format( assistant1 | random, feature_week_name, program_name, commands_text~"这个使用习惯" if commands_text else "" ), "{0},小优准备了你{1}的{2}程序,{3}赶快启动吧!".format( assistant2 | random, feature_week_name, program_name, commands_text~"," if commands_text else "" ) ] | random}} {% elif recommend_type |upper == "POPULAR" %} {{ [ "{0},给你准备了{1}人气最高的{2}程序。".format(assistant1 | random, city, program_name), "{0},这个时间{1}程序在{2}使用率最高哦。".format(assistant2 | random, program_name, city), "{0}好呀,为你推荐{1}人气最高的{2}程序。".format(period, city, program_name), "嗨,小优发现这个时间{0},{1}程序人气最高哦。".format(city, program_name), "{0}洗衣推荐来啦,{1}程序是{2}当前的热门程序哦。".format(season, program_name, city) ] | random }} {% elif recommend_type |upper == "CUSTOM" %} {%set commands_text = commands_params(changed_params)%} {{ [ "{0}好呀,小优发现你{1}{2}程序,{3}给你准备好了。".format(period, feature_name, program_name, commands_text~"," if commands_text else ""), "{0}好呀,小优准备了你{1}的{2}程序。{3}".format(period, feature_name, program_name, commands_text~"。" if commands_text else ""), "{0},推荐你{1}的{2}程序。{3}".format(assistant1 | random, feature_name, program_name, commands_text~"。" if commands_text else ""), "{0},为你准备了你{1}的{2}程序。{3}".format(assistant1 | random, feature_name, program_name, commands_text~"。" if commands_text else ""), "{0},你{1}的{2}程序,{3}已经准备就绪。".format(assistant2 | random, feature_name, program_name, commands_text if commands_text else "") ]| random }} {% endif %} {% else %} 抱歉,ID为'{{ program_id }}'的程序不存在或暂未收录。 {% endif %} {% endset %} {%- endmacro %} {# --------------------- 人气模板 --------------------- #} {% macro popular(period, city, program_id, count, user_count, user_proportion) -%} {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {% set count = count_round(count) | int %} {% set user_count = count_round(user_count) |int %} {% set user_proportion = user_proportion | int %} {% if program_name %} {{ [ "{0}好呀,为你推荐{1}人气最高的{2}程序。{3}".format( period, city, program_name, ("近期有" ~ user_count ~ "多" ~ (user1 | random) ~ "都喜欢用呢。" if user_count >= 30 else "") ), "{0}好呀,为你推荐{1}人气最高的{2}程序。{3}".format( period, city, program_name, ("近期有" ~ approx_fraction(user_proportion) ~ "的" ~ (user2 | random) ~ "都喜欢用呢。" if user_proportion >= 30 else "") ), "{0}好呀,小优发现{1}程序在{2}的人气很高哦,{3}咱也来试试吧!".format( period, program_name, city, ("近期有" ~ count ~"多次使用记录呢," if count >= 100 else "") ), "{0},给你准备了{1}人气最高的{2}程序,{3}".format( assistant1 |random, city, program_name, ("近期有"~ user_count ~"多" ~ (user1 | random) ~ "都喜欢用呢。咱们也来试试看吧!" if user_count >= 30 else "快来试试看吧!") ), "{0},{1}程序在{2}很受欢迎呢,{3}咱们也来试试看吧!".format( assistant1 |random, program_name, city, ("是" ~ user_count ~"多"~ (user1 | random) ~ "的共同选择。" if user_count >= 30 else "") ), "{0},{1},这个时间段{2}在{3}人气最高,{4}给你也准备好了。".format( greeting | random, assistant1 | random, program_name, city, ("超过" ~ approx_fraction(user_proportion) ~ "的" ~ (user2 |random) ~ "都在用呢," if user_proportion >= 30 else "") ), "{0},为你推荐当前人气最高的{1}程序,{2}".format( assistant2 | random, program_name, (city ~ "超过"~ approx_fraction(user_proportion) ~"的"~ (user2 |random) ~"都在用哦" if user_proportion >= 30 else "都准备好了,直接启动就行。") ), "{0},给你准备了{1}人气最高的{2}程序,{3}".format( assistant2 | random, city, program_name, ("近期有"~ user_count ~"多" ~ (user1 | random) ~ "都喜欢用呢。咱们也来试试看吧!" if user_count >= 30 else "快启动试试吧!") ), "{0},{1}程序在{2}人气最高,{3}咱们也来试试看吧!".format( assistant2 | random, program_name, city, ("是"~ user_count ~"多"~ (user1 | random) ~ "的共同选择。" if user_count >= 30 else "") ), "{0},{1},{2}程序给你准备好了,{3}快来试试看吧!".format( greeting | random, assistant2 | random, program_name, ("这个时间"~ city ~"有超过"~ approx_fraction(user_proportion) ~"的"~ (user2 |random) ~"都在用它," if user_proportion >= 30 else "") ), "{0}好呀,根据全网用户的使用偏好,我帮你选好了{1}程序,你放心用就好了。".format( period, program_name ), "{0}好呀,小优发现大家都爱用{1}程序,今天我们也来试试吧。".format( period, program_name ), "{0},为你准备好了全网使用率最高的{1}程序,来试试效果怎么样吧。".format( assistant1 | random, program_name ), "{0}!{1},{2}程序程序很受欢迎,给你也准备好了,快启动体验一下吧".format( greeting | random, assistant2 | random, program_name ), "{0}!{1},今天我们来试试这个人气最高的程序吧。".format( greeting | random, assistant2 | random ) ] | random }} {% else %} 抱歉,ID为'{{ program_id }}'的程序不存在或暂未收录。 {% endif %} {%- endmacro %} {# --------------------- 定制模板 --------------------- #} {% macro custom(period, city, program_id, feature_name, changed_params,count, user_count, user_proportion) -%} {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {% if program_name %} {% if feature_name!="" %} {# 干燥度枚举映射 #} {% set dry_level_map = { "1": "即熨", "2": "即穿", "3": "储藏", "4": "特干" } %} {# 温度枚举映射 #} {% set dry_temp_map = { "1": "冷风", "2": "低温", "3": "中温", "4": "高温" } %} {# 烘干参数对应关系 #} {# {% set commands_text = [ "水温{}度".format(changed_params.setTemp) if changed_params.setTemp and changed_params.setTemp != "0" else "", "转速{}转".format(changed_params.speed) if changed_params.speed and changed_params.speed != "0" else "", "漂洗{}次".format(changed_params.spinTime) if changed_params.spinTime and changed_params.spinTime != "0" else "", "洗涤{}分钟".format(changed_params.washTime) if changed_params.washTime and changed_params.washTime != "0" else "" ] | reject("equalto", "") | join(",")%} #} {% set commands_text = [ "干燥度:{}".format(dry_level_map.get(changed_params.DryLevel)) if changed_params.DryLevel and changed_params.DryLevel != "0" else "", "温度:{}".format(dry_temp_map.get(changed_params.DryTemp)) if changed_params.DryTemp and changed_params.DryTemp != "0" else "", "风力{}挡".format(changed_params.FanLevel) if changed_params.FanLevel and changed_params.FanLevel != "0" else "" ] | reject("equalto", "") | join(",")%} {{ [ "{0}好呀,小优发现你{1}{2}程序,{3}给你准备好了。".format( period, feature_name, program_name, commands_text~"," if commands_text else "" ), "{0}好呀,小优准备了你{1}的{2}程序。{3}快来启动吧".format( period, feature_name, program_name, commands_text~"。" if commands_text else "" ), "{0}好呀,{1}程序已经准备就绪了,它可是你{2}的程序。{3}赶快启动吧".format( period, program_name, feature_name, commands_text~"的习惯参数也帮你设置好了。" if commands_text else "" ), "{0},{1},推荐你{2}的{3}程序,{4}".format( greeting | random, assistant1 | random, feature_name, program_name, commands_text~"。" if commands_text else "" ), "{0},{1},为你准备了你{2}的{3}程序。{4}".format( greeting | random, assistant1 | random, feature_name, program_name, commands_text~"。" if commands_text else "" ), "{0},你{1}的{2}程序{3}".format( assistant2 | random, feature_name, program_name, "和"~commands_text~"的习惯参数给你准备好了。" if commands_text else ",给你准备好了。" ), "{0},为你推荐{1}的{2}程序,{3}赶快启动吧!".format( assistant2 | random, feature_name, program_name, commands_text~"。" if commands_text else "" ), "{0},你{1}的{2}程序,{3}已经准备就绪。".format( assistant2 | random, feature_name, program_name, commands_text~"。" if commands_text else "" ), "我发现你喜欢这么用,我给你准备好了,现在开始烘干吗?", "又是为你贴心服务的一天,今天为你专属定制{0}程序,{1}赶快启动吧。".format( program_name, commands_text~"。" if commands_text else "" ), ]| random }} {% else %} {{"你好,推荐您常用的{0}程序,已准备好了,快开始启动吧。"format(program_name)}} {% endif %} {% else %} 抱歉,ID为'{{ program_id }}'的程序不存在或暂未收录。 {% endif %} {%- endmacro %} {# --------------------- 天气拼接模板 --------------------- #} {#根据推荐类型拼接对应简短模板#} {# {{ [ prefix_message |trim, [ [ "今天阴天,晾晒衣物会比较慢,帮你打开洗烘联动啦。", "今天阴天,晾晒衣物会比较慢,洗烘联动更省心哦。" ] | random if weather == '阴' and wash_dry_link else "今天阴天,室外晾晒衣物会比较慢,建议您在室内晾晒。" if weather == '阴' else [ "今天预报有{},不适合室外晾晒,帮你打开洗烘联动啦。".format(weather), "今天预报有{},不适合室外晾晒,洗烘联动更省心哦。".format(weather) ] | random if weather in ['小雨','中雨','大雨','暴雨','小雪','中雪','大雪','暴雪'] and wash_dry_link else "天气预报今天有{},建议您在室内晾晒。".format(weather) if weather in ['小雨','中雨','大雨','暴雨','小雪','中雪','大雪','暴雪'] else [ "今天有{},室外晾晒容易导致二次污染,帮你打开洗烘联动啦。".format(weather), "今天有{},室外晾晒容易导致二次污染,洗烘联动更省心哦。".format(weather) ] | random if weather in ['雾霾','中度雾霾','重度雾霾','沙尘'] and wash_dry_link else "天气预报今天有{},室外晾晒容易导致二次污染,建议您在室内晾晒。".format(weather) if weather in ['雾霾','中度雾霾','重度雾霾','沙尘'] else [ "今天天气不太好,帮你打开洗烘联动啦。", "今天天气不太好,洗烘联动更省心哦。" ] | random if wash_dry_link else "今天天气不太好,建议您在室内晾晒。" ] | first ]| reject("equalto", "") | join("") }} #} {# --------------------- 季节模板 --------------------- #} {% macro dry_season(time_term, filter_rule_code, program_id) -%} {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {{ [ "立春启新,暖意渐浓!轻盈的春装该提前准备了。{}".format( "为您推荐"~program_name~"程序,烘干同时守护面料防水性能,春日出行清爽随行。" if program_name == '冲锋衣' else "") if time_term == '立春' and filter_rule_code== 'time_season_in' else "立春时节,天气渐暖。厚重冬衣,烘干后收纳才靠谱。{}".format( "为您推荐"~program_name~"程序,将冬日暖意妥善封存。" if program_name in ["羽绒","羊毛"] else "") if time_term == '立春' and filter_rule_code== 'time_season_storage' else "立夏时节,暑气渐长。轻薄的夏日穿搭该提前准备好啦。{}".format( "为您推荐"~program_name~"程序,低温烘干防止变形起皱,让您的夏日穿搭清爽挺括。" if program_name == "丝绸" else "") if time_term == '立夏' and filter_rule_code== 'time_season_in' else "立夏潮闷,春装收纳正当时。{}".format( "推荐使用"~program_name~"程序,彻底烘干衣物潮气与风尘,防止霉变,便于安心久存。" if program_name == '冲锋衣' else "") if time_term == '立夏' and filter_rule_code== 'time_season_storage' else "立秋已至,暑去凉来。是时候取出压箱底的秋装,准备添衣了。{}".format( "为您推荐"~program_name~"程序,守护面料防水与防风性能,伴您从容出行。" if program_name == '冲锋衣' else "") if time_term == '立秋' and filter_rule_code== 'time_season_in' else "立秋换季,夏装可以功成身退啦。{}".format( "推荐使用"~program_name~"程序,低温烘干防止衣物变形,帮您留住夏日风采~" if program_name == "丝绸" else "") if time_term == '立秋' and filter_rule_code== 'time_season_storage' else "立冬安康,寒潮将至。保暖的冬装该登场了。{}".format( "为您推荐"~program_name~"程序,均匀烘干去除潮气,让衣物恢复蓬松柔软,为您锁住冬日温暖。" if program_name in ["羊毛","羽绒"] else "") if time_term == '立冬' and filter_rule_code== 'time_season_in' else "立冬时节,薄款秋装该收纳入库啦。{}".format( "为您推荐"~program_name~"程序,温和烘干去除潮气,让衣物处于最佳储存状态,静待明年春日。" if program_name == '冲锋衣' else "") if time_term == '立冬' and filter_rule_code== 'time_season_storage' ]| first}} {%- endmacro %} {#----------------关怀-----------------#} {% macro dry_care(program_id, DryNight, WFreeCn) -%} {% set name_dry = "夜间烘" %} {% set name_wind = "延取防皱" %} {% set night_dry = DryNight if DryNight !="0" else ""%} {% set wind_cruise = WFreeCn if WFreeCn !="0" else ""%} {{ [prefix_message |trim, [ ["夜深了,帮你打开{0}和{1}功能啦。".format(name_dry, name_wind) , "时间有点晚了,已为你开启{0}和{1},衣物久放也不皱。".format(name_dry, name_wind), "{0}已开启,静音干衣,{1}为您守护衣物至天明。".format(name_dry, name_wind), "已开启{0},自动降噪并开启{1}防止褶皱。".format(name_dry, name_wind) ] |random if night_dry and wind_cruise else ["夜深了,帮你打开{0}啦,静音不扰眠。".format(name_dry), "时间有点晚了,我会静悄悄的。", "夜间干衣,已自动开启静音功能,守护您的安宁。", "夜间烘也准备好了,干衣机会低噪运行,让您静享安宁。" ] |random if night_dry else ["夜深了,帮你打开{},智能保管衣物。".format(name_wind) , "时间有点晚了,{}功能帮你守护衣物到天明。".format(name_wind), "夜间干衣,帮你打开{}了,衣物久放也不用怕。".format(name_wind), "{}也准备好了,烘干完成会帮你智能保管衣物。".format(name_wind) ]|random if wind_cruise else "" ] | first] | reject("equalto", "") | join("") }} {%- endmacro %} {#-----------环保---------------#} {% macro dry_env() -%} {{ [prefix_message |trim,"马上就到错峰用电时间段了,建议您预约烘干。"] |reject("equalto", "") | join("")}} {%- endmacro %} {#-----------健康---------------#} {# {% macro wash_health(program_id) -%} {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {{"你的洗衣机该清洁了,快启用{}程序给它洗个澡吧!注意不要放入衣服和洗衣液哦。".format(program_name)}} {%- endmacro %} #} {# --------------------- 拼接模板测试 --------------------- #} {# {% macro add_test(period, city, program_id, season,card_type="popularity") -%} {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {{ [ brief_popularity_message(city, program_name, period, season) if card_type == "popularity" else brief_custom_message(city, program_name, period, season) , [ "你好这是拼接测试", "你好这是拼接测试2" ]|random ]| reject("equalto", "") | join("") }} {%- endmacro %} {# --------------------- 拼接模板测试2 --------------------- #} {% macro add_test2(period, city, program_id, season,card_type, changed_params) -%} {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {{ [ message, [ "你好这是拼接测试", "你好这是拼接测试2" ]|random ]| reject("equalto", "") | join("") }} {%- endmacro %} #} {# ----------------参数组合 ----------------#} {# {% macro custom_param_group(temperature, spinSpeed, rinseTimes, mainWashTime) -%} {{ [ "水温{}度".format(temperature) if temperature and temperature != "0" else "", "转速{}转".format(spinSpeed) if spinSpeed and spinSpeed != "0" else "", "漂洗{}次".format(rinseTimes) if rinseTimes and rinseTimes != "0" else "", "洗涤{}分钟".format(mainWashTime) if mainWashTime and mainWashTime != "0" else "" ] | reject("equalto", "") | join(",") }} {%- endmacro %} #}