
用 Python 构建节日国风服饰销量模拟程序对端午节、中秋节、春节三大节日模拟汉服与新中式服饰的峰值销量并以中立视角呈现完整分析过程。一、实际应用场景描述在《时尚产业与品牌创新》课程中节日经济与季节性爆发是服饰零售的核心议题。国风服饰的节日效应尤为显著- 春节农历正月汉服租赁与销售双高峰小红书新年汉服搜索量在腊月暴涨 300%新中式旗袍、改良唐装是拜年、聚会的热门选择。- 端午节农历五月龙舟赛、祭屈原等民俗活动带动楚风汉服战国袍销量脉冲式增长但持续时间短仅节前 1-2 周。- 中秋节农历八月月下飞天敦煌飞天主题汉服成为中秋游园会、灯会的热门装扮与赏月、诗词文化深度绑定。品牌与电商平台面临核心问题三大节日的国风服饰销量峰值各是多少汉服 vs 新中式哪个节日爆发力更强库存该如何提前备货二、引入痛点- 节日销量受多因子耦合影响假期长度、文化热度、天气、社交媒体话题量单靠历史同比无法拆解各因子贡献。- 汉服与新中式的节日敏感性不同——汉服在传统节日爆发力更强新中式在春节跨场景商务拜年家庭聚会更占优势缺乏量化对比框架。- 缺乏库存预警模型——备货不足错失销售窗口备货过多节后库存积压。⇒ 用 Python 构建多因子节日销量模拟引擎 Monte Carlo 不确定性量化 库存决策建议输出三大节日 × 两类服饰的峰值销量矩阵。三、核心逻辑讲解1. 销量模拟公式节日峰值销量 基线销量 × 节日放大系数 × 天气系数 × 社交热度系数 × 品类适配系数其中- 基线销量该城市/渠道日常销量- 节日放大系数该节日对国风服饰的文化驱动力- 天气系数气温/降水对穿着意愿的影响- 社交热度系数小红书/抖音话题量模拟- 品类适配系数汉服 vs 新中式对该节日的适配度2. 三大节日 × 两类服饰的特征矩阵汉服 新中式春节 拜年/庙会/汉服走亲访友极高爆发 旗袍/改良唐装商务拜年家庭聚会高爆发端午 龙舟赛/楚文化主题脉冲式短爆发 适配度一般小幅拉动中秋 游园会/赏月/飞天主题中度爆发 月下主题新中式中度拉动3. 不确定性量化Monte Carlo 模拟 N10000 次- 节日放大系数 ±20% 随机扰动- 社交热度系数 ±30% 随机扰动- 天气系数 ±15% 随机扰动输出P10 / P50 / P90 销量区间 → 库存决策依据四、代码模块化festival_fashion_simulator.py#!/usr/bin/env python3# -*- coding: utf-8 -*-festival_fashion_simulator.py节日国风服饰销量模拟程序计算端午/中秋/春节 汉服与新中式服饰峰值销量依赖: numpy, pandas, matplotlib安装: pip install numpy pandas matplotlibimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom matplotlib import rcParamsfrom dataclasses import dataclass, fieldfrom typing import Dict, List, Tuple, Optionalfrom enum import EnumrcParams[font.sans-serif] [Noto Sans CJK SC, SimHei, Microsoft YaHei]rcParams[axes.unicode_minus] False# ──────────────────────────────────────────────# 1. 枚举与数据结构# ──────────────────────────────────────────────class Festival(Enum):节日SPRING_FESTIVAL 春节DRAGON_BOAT 端午节MID_AUTUMN 中秋节class GarmentType(Enum):服饰品类HANFU 汉服NEW_CHINESE 新中式dataclassclass CityProfile:城市画像用于销量模拟name: strregion: strbaseline_daily_sales: int # 日常基线日销量件spring_festival_boost: float # 春节放大系数dragon_boat_boost: float # 端午放大系数mid_autumn_boost: float # 中秋放大系数avg_temp_spring: float # 春节均温影响穿着意愿avg_temp_dragon: float # 端午均温avg_temp_autumn: float # 中秋均温rainfall_dragon: float # 端午降水概率rainfall_autumn: float # 中秋降水概率social_media_index: float # 社交媒体话题活跃度0-100dataclassclass GarmentProfile:服饰品类画像garment_type: GarmentType# 各节日品类适配系数0-1spring_festival_fit: floatdragon_boat_fit: floatmid_autumn_fit: float# 价格区间avg_price: float# 生产提前期天lead_time_days: int# 库存周转天数turnover_days: int# ──────────────────────────────────────────────# 2. 数据库模块# ──────────────────────────────────────────────class FestivalDatabase:节日国风服饰数据库基于行业报告与电商数据综合构建staticmethoddef get_city_profiles() - Dict[str, CityProfile]:主要城市节日消费画像return {北京: CityProfile(name北京, region华北,baseline_daily_sales120,spring_festival_boost4.5, # 庙会/拜年文化强dragon_boat_boost1.8, # 北方端午氛围一般mid_autumn_boost2.8, # 中秋赏月文化浓厚avg_temp_spring-2, avg_temp_dragon26, avg_temp_autumn18,rainfall_dragon0.25, rainfall_autumn0.20,social_media_index85),上海: CityProfile(name上海, region华东,baseline_daily_sales150,spring_festival_boost3.8, # 商圈活动多dragon_boat_boost2.5, # 江南端午氛围好mid_autumn_boost3.5, # 豫园灯会等avg_temp_spring5, avg_temp_dragon28, avg_temp_autumn22,rainfall_dragon0.35, rainfall_autumn0.25,social_media_index95),成都: CityProfile(name成都, region西南,baseline_daily_sales100,spring_festival_boost4.0, # 锦里/宽窄巷子dragon_boat_boost2.2, # 适中mid_autumn_boost3.2, # 杜甫草堂赏月avg_temp_spring8, avg_temp_dragon27, avg_temp_autumn20,rainfall_dragon0.45, rainfall_autumn0.40,social_media_index80),广州: CityProfile(name广州, region华南,baseline_daily_sales90,spring_festival_boost3.5, # 花市庙会dragon_boat_boost3.0, # 南方端午龙舟赛热度高mid_autumn_boost3.8, # 南方中秋更重视avg_temp_spring15, avg_temp_dragon32, avg_temp_autumn26,rainfall_dragon0.50, rainfall_autumn0.35,social_media_index75),西安: CityProfile(name西安, region西北,baseline_daily_sales110,spring_festival_boost5.0, # 大唐不夜城古都氛围dragon_boat_boost2.0, # 适中mid_autumn_boost3.0, # 大唐芙蓉园avg_temp_spring2, avg_temp_dragon28, avg_temp_autumn20,rainfall_dragon0.30, rainfall_autumn0.25,social_media_index88)}staticmethoddef get_garment_profiles() - Dict[GarmentType, GarmentProfile]:服饰品类画像return {GarmentType.HANFU: GarmentProfile(garment_typeGarmentType.HANFU,spring_festival_fit0.92, # 春节庙会/拜年极高适配dragon_boat_fit0.85, # 龙舟赛/楚文化主题mid_autumn_fit0.88, # 游园会/赏月avg_price580,lead_time_days45,turnover_days30),GarmentType.NEW_CHINESE: GarmentProfile(garment_typeGarmentType.NEW_CHINESE,spring_festival_fit0.78, # 商务拜年家庭聚会dragon_boat_fit0.55, # 适配度一般mid_autumn_fit0.72, # 月下主题avg_price420,lead_time_days30,turnover_days25)}staticmethoddef get_festival_meta() - Dict[Festival, Dict]:节日元信息return {Festival.SPRING_FESTIVAL: {duration_days: 15, # 腊月廿三到正月十五peak_window_days: 5, # 除夕到初四cultural_driver: 95, # 文化驱动力0-100social_spike: 3.5, # 社交话题爆发倍数weather_sensitivity: 0.15, # 天气敏感度description: 春节家国同庆汉服拜年/庙会成为新民俗},Festival.DRAGON_BOAT: {duration_days: 7, # 节前3天到节后3天peak_window_days: 2, # 端午当天前1天cultural_driver: 60,social_spike: 2.0,weather_sensitivity: 0.25, # 户外赛事天气影响大description: 端午龙舟竞渡楚文化脉冲式短爆发},Festival.MID_AUTUMN: {duration_days: 10, # 节前5天到节后5天peak_window_days: 3, # 中秋当天前后各1天cultural_driver: 75,social_spike: 2.8,weather_sensitivity: 0.10,description: 中秋月下飞天游园赏月诗意驱动}}# ──────────────────────────────────────────────# 3. 销量模拟引擎模块# ──────────────────────────────────────────────class SalesSimulator:节日国风服饰销量模拟引擎核心多因子乘法模型 Monte Carlo 不确定性量化def __init__(self,city_db: Dict[str, CityProfile],garment_db: Dict[GarmentType, GarmentProfile],festival_db: Dict[Festival, Dict]):self.city_db city_dbself.garment_db garment_dbself.festival_db festival_db# 天气系数查找表基于温度舒适度self.temp_comfort_map {# (min_temp, max_temp) → 穿着意愿系数(-10, 0): 0.85, # 偏冷厚重汉服OK(0, 10): 0.95, # 舒适(10, 20): 1.05, # 很舒适(20, 30): 1.00, # 适中(30, 40): 0.75, # 偏热厚重汉服不利}def _calc_weather_factor(self,city: CityProfile,festival: Festival) - float:计算天气系数temp_map {Festival.SPRING_FESTIVAL: city.avg_temp_spring,Festival.DRAGON_BOAT: city.avg_temp_dragon,Festival.MID_AUTUMN: city.avg_temp_autumn}rain_map {Festival.SPRING_FESTIVAL: 0.15, # 春节降水少Festival.DRAGON_BOAT: city.rainfall_dragon,Festival.MID_AUTUMN: city.rainfall_autumn}temp temp_map[festival]rain_prob rain_map[festival]# 温度舒适度comfort 1.0for (t_min, t_max), factor in self.temp_comfort_map.items():if t_min temp t_max:comfort factorbreak# 降水惩罚户外穿着意愿下降rain_penalty 1.0 - rain_prob * 0.3# 节日天气敏感度sensitivity self.festival_db[festival][weather_sensitivity]weather_factor 1.0 (comfort - 1.0) * (1 - sensitivity) \(rain_penalty - 1.0) * sensitivityreturn max(0.5, min(1.5, weather_factor))def _calc_social_factor(self,city: CityProfile,festival: Festival) - float:计算社交热度系数base_social city.social_media_index / 100.0social_spike self.festival_db[festival][social_spike]return base_social * social_spikedef simulate_deterministic(self,city_name: str,festival: Festival,garment_type: GarmentType) - Dict:确定性模拟单点估计返回完整的销量明细if city_name not in self.city_db:raise ValueError(f城市 {city_name} 不在数据库中)city self.city_db[city_name]garment self.garment_db[garment_type]fest_meta self.festival_db[festival]# 基线日销量baseline city.baseline_daily_sales# 节日放大系数boost_map {Festival.SPRING_FESTIVAL: city.spring_festival_boost,Festival.DRAGON_BOAT: city.dragon_boat_boost,Festival.MID_AUTUMN: city.mid_autumn_boost}festival_boost boost_map[festival]# 品类适配系数fit_map {Festival.SPRING_FESTIVAL: garment.spring_festival_fit,Festival.DRAGON_BOAT: garment.dragon_boat_fit,Festival.MID_AUTUMN: garment.mid_autumn_fit}garment_fit fit_map[festival]# 天气系数weather_factor self._calc_weather_factor(city, festival)# 社交热度系数social_factor self._calc_social_factor(city, festival)# 文化驱动力culture_driver fest_meta[cultural_driver] / 100.0# 综合计算peak_daily_sales (baseline* festival_boost* garment_fit* weather_factor* social_factor* culture_driver)peak_daily_sales int(round(peak_daily_sales))# 节日总销量峰值 × 持续天数total_festival_sales int(peak_daily_sales * fest_meta[duration_days])# 峰值窗口销量最核心的几天peak_window_sales int(peak_daily_sales * fest_meta[peak_window_days])return {city: city_name,festival: festival.value,garment: garment_type.value,baseline_daily: baseline,festival_boost: round(festival_boost, 2),garment_fit: round(garment_fit, 2),weather_factor: round(weather_factor, 3),social_factor: round(social_factor, 2),culture_driver: round(culture_driver, 2),peak_daily_sales: peak_daily_sales,total_festival_sales: total_festival_sales,peak_window_sales: peak_window_sales,festival_duration: fest_meta[duration_days],peak_window_days: fest_meta[peak_window_days],avg_price: garment.avg_price,peak_daily_revenue: round(peak_daily_sales * garment.avg_price, 2),total_festival_revenue: round(total_festival_sales * garment.avg_price, 2),lead_time_days: garment.lead_time_days,turnover_days: garment.turnover_days}def simulate_monte_carlo(self,city_name: str,festival: Festival,garment_type: GarmentType,n_simulations: int 10000,seed: int 42) - pd.DataFrame:Monte Carlo 模拟对关键参数注入随机扰动输出销量分布np.random.seed(seed)city self.city_db[city_name]garment self.garment_db[garment_type]fest_meta self.festival_db[festival]baseline city.baseline_daily_salesboost_map {Festival.SPRING_FESTIVAL: city.spring_festival_boost,Festival.DRAGON_BOAT: city.dragon_boat_boost,Festival.MID_AUTUMN: city.mid_autumn_boost}fit_map {Festival.SPRING_FESTIVAL: garment.spring_festival_fit,Festival.DRAGON_BOAT: garment.dragon_boat_fit,Festival.MID_AUTUMN: garment.mid_autumn_fit}results []for _ in range(n_simulations):# 随机扰动noise_boost np.random.normal(1.0, 0.20)noise_social np.random.normal(1.0, 0.30)noise_weather np.random.normal(1.0, 0.15)festival_boost boost_map[festival] * max(0.5, noise_boost)garment_fit fit_map[festival]weather_factor self._calc_weather_factor(city, festival) * noise_weathersocial_factor self._calc_social_factor(city, festival) * noise_socialculture_driver fest_meta[cultural_driver] / 100.0peak_daily (baseline * festival_boost * garment_fit *max(0.5, weather_factor) * social_factor * culture_driver)total_sales peak_daily * fest_meta[duration_days]window_sales peak_daily * fest_meta[peak_window_days]revenue total_sales * garment.avg_priceresults.append({peak_daily: max(0, int(round(peak_daily))),total_sales: max(0, int(round(total_sales))),window_sales: max(0, int(round(window_sales))),revenue: max(0, revenue),peak_revenue: max(0, peak_daily * garment.avg_price)})return pd.DataFrame(results)def batch_simulate_all(self) - pd.DataFrame:全城市 × 全节日 × 全品类 批量模拟rows []for city_name in self.city_db:for festival in Festival:for garment_type in GarmentType:result self.simulate_deterministic(city_name, festival, garment_type)rows.append(result)return pd.DataFrame(rows)# ──────────────────────────────────────────────# 4. 库存决策模块# ──────────────────────────────────────────────class InventoryAdvisor:库存决策建议staticmethoddef recommend_inventory(sim_result: Dict,mc_df: pd.DataFrame) - Dict:基于模拟结果给出库存建议p50_total int(np.percentile(mc_df[total_sales], 50))p75_total int(np.percentile(mc_df[total_sales], 75))p90_total int(np.percentile(mc_df[total_sales], 90))p50_daily int(np.percentile(mc_df[peak_daily], 50))p75_daily int(np.percentile(mc_df[peak_daily], 75))lead_time sim_result[lead_time_days]turnover sim_result[turnover_days]# 备货建议P75 总销量 安全库存safety_stock int(p75_total * 0.15)recommended_stock p75_total safety_stock# 库存天数stock_days recommended_stock / p50_daily if p50_daily 0 else 0# 积压风险if stock_days sim_result[festival_duration] turnover:risk_level 高risk_desc 节后库存积压风险较大建议保守备货elif stock_days sim_result[festival_duration]:risk_level 中risk_desc 适度备货节后需配合促销活动else:risk_level 低risk_desc 库存周转健康可适度追加备货return {p50_total: p50_total,p75_total: p75_total,p90_total: p90_total,p50_daily: p50_daily,p75_daily: p75_daily,recommended_stock: recommended_stock,safety_stock: safety_stock,stock_days: round(stock_days, 1),risk_level: risk_level,risk_desc: risk_desc,lead_time_days: lead_time,turnover_days: turnover,pre_order_date: f节前 {lead_time} 天}# ──────────────────────────────────────────────# 5. 可视化仪表盘模块# ──────────────────────────────────────────────class Dashboard:节日销量模拟可视化仪表盘FESTIVAL_COLORS {春节: #E74C3C,端午节: #2ECC71,中秋节: #F39C12}GARMENT_COLORS {汉服: #8B4513,新中式: #1ABC9C}classmethoddef plot_dashboard(cls,sim_result: Dict,mc_df: pd.DataFrame,inventory: Dict,batch_df: pd.DataFrame,city_name: str,filename: str festival_sales_dashboard.png):fig plt.figure(figsize(24, 20))title (f节日国风服饰销量模拟 — {city_name}f{sim_result[garment]})fig.suptitle(title, fontsize20, fontweightbold, y0.99)# ── 图1销量分布直方图 ──ax1 fig.add_subplot(2, 3, 1)cls._plot_sales_distribution(ax1, mc_df)# ── 图2因子分解瀑布图 ──ax2 fig.add_subplot(2, 3, 2)cls._plot_factor_waterfall(ax2, sim_result)# ── 图3三大节日对比该城市该品类 ──ax3 fig.add_subplot(2, 3, 3)cls._plot_festival_comparison(ax3, batch_df, city_name)# ── 图4汉服 vs 新中式该城市各节日 ──ax4 fig.add_subplot(2, 3, 4)cls._plot_garment_comparison(ax4, batch_df, city_name)# ── 图5全国城市热力图 ──ax5 fig.add_subplot(2, 3, 5)cls._plot_city_heatmap(ax5, batch_df)# ── 图6库存决策卡片 ──ax6 fig.add_subplot(2, 3, 6)cls._plot_inventory_card(ax6, sim_result, inventory)plt.tight_layout(rect[0, 0, 1, 0.96])plt.savefig(filename, dpi150, bbox_inchestight)plt.show()print(f[INFO] 仪表盘已保存: {filename})classmethoddef _plot_sales_distribution(cls, ax, mc_df: pd.DataFrame):Monte Carlo 销量分布total mc_df[total_sales]ax.hist(total, bins50, color#3498db, alpha0.7, edgecolorwhite)for pct, color, label in [(10, #e74c3c, P10),(50, #2ecc71, P50),(90, #f39c12, P90)]:val np.percentile(total, pct)ax.axvline(xval, colorcolor, linestyle--, linewidth1.5)ax.annotate(f{label}: {int(val)},xy(val, ax.get_ylim()[1] * 0.9),fontsize8, colorcolor, fontweightbold,hacenter)ax.set_xlabel(节日总销量件)ax.set_ylab利用AI解决实际问题如果你觉得这个工具好用欢迎关注长安牧笛