改写Preference

代码如下:

import android.content.Context;
import android.preference.Preference;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.tcad.marketassistant.R;

public class CommentsPreference extends Preference {

	private LayoutInflater inflater;
	
	private String rating;
	
	private String author;
	
	private String date;
	
	private String content;
	
	public CommentsPreference(Context context) {
		super(context);
	
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	protected View onCreateView(ViewGroup parent) {
		
		View v = inflater.inflate(R.layout.comments, null);
		
		RatingBar r = (RatingBar)v.findViewById(R.id.com_rating);
		
		TextView a = (TextView)v.findViewById(R.id.com_author);
		
		TextView d = (TextView)v.findViewById(R.id.com_date);
		
		TextView c = (TextView)v.findViewById(R.id.com_content);
		
		if(rating!=null){
			
			r.setRating(Float.parseFloat(rating));
		}
		if(author!=null){
			
			a.setText(author);
		}
		if(date!=null){
			
			d.setText(date);
		}
		if(content!=null){
			
			c.setText(content);
		}
		return v;
	}

	public void setRaingAuthorDateContent(String rating,String author,String date,String content){
		
		this.rating = rating;
		
		this.author = author;
		
		this.date = date;
		
		this.content = content;
		
	}
}

  需要注意的是在onCreateView而不是onBindView中

# 自动售货机市场运营数据分析 - 完整代码 # 导入必要的库 import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # 1. 数据加载 file_path = 'vending_machine_sales.csv' wujing_df = pd.read_csv(file_path) # 2. 数据结构探索 print("数据基本信息:") print(wujing_df.info()) print("\n描述性统计:") print(wujing_df.describe(include='all')) # 3. 数据处理 # 3.1 检查并处理重复值 print(f"是否存在重复值:{wujing_df.duplicated().any()}") wujing_df = wujing_df.drop_duplicates() # 3.2 处理缺失值 missing_values = wujing_df.isnull().sum() print(f"缺失值统计:\n{missing_values[missing_values > 0]}") wujing_df = wujing_df.dropna() # 或者使用填充方法,例如 wujing_df.fillna(0) # 3.3 检查并处理异常值 numeric_columns = ['RPrice', 'RQty', 'MPrice', 'MQty', 'LineTotal', 'TransTotal'] for col in numeric_columns: plt.figure(figsize=(10, 6)) sns.boxplot(wujing_df[col]) plt.title(f'Boxplot for {col}') plt.show() # 根据箱线图结果处理异常值,例如删除或修正 wujing_df = wujing_df[(wujing_df['RPrice'] < wujing_df['RPrice'].quantile(0.99)) & (wujing_df['RPrice'] > wujing_df['RPrice'].quantile(0.01))] # 4. 数据分析 # 4.1 各个机器卖出的各种食物的销售总额分析 wujing_sales_summary = wujing_df.groupby(['Location', 'Machine', 'Product'])['TransTotal'].sum().reset_index() wujing_sales_summary_sorted = wujing_sales_summary.sort_values(by='TransTotal', ascending=False) print("销售总额最高的前10项:") print(wujing_sales_summary_sorted.head(10)) # 4.2 可视化不同位置的用户消费偏好 # 4.2.1 不同位置的用户喜欢购买的产品 wujing_product_preference = wujing_df.groupby(['Location', 'Product']).size().reset_index(name='count') wujing_most_preferred_products = wujing_product_preference.loc[wujing_product_preference.groupby('Location')['count'].idxmax()] plt.figure(figsize=(12, 8)) sns.barplot(x='Location', y='count', hue='Product', data=wujing_most_preferred_products) plt.title('Most Preferred Products by Location') plt.xticks(rotation=45) plt.show() # 4.2.2 不同位置用户的支付方式偏好 wujing_payment_preference = wujing_df.groupby(['Location', 'Type']).size().reset_index(name='count') wujing_preferred_payment_methods = wujing_payment_preference.loc[wujing_payment_preference.groupby('Location')['count'].idxmax()] plt.figure(figsize=(12, 8)) sns.barplot(x='Location', y='count', hue='Type', data=wujing_preferred_payment_methods) plt.title('Preferred Payment Methods by Location') plt.xticks(rotation=45) plt.show() # 4.2.3 不同位置用户的喜欢的产品类型 wujing_category_preference = wujing_df.groupby(['Location', 'Category']).size().reset_index(name='count') wujing_preferred_categories = wujing_category_preference.loc[wujing_category_preference.groupby('Location')['count'].idxmax()] plt.figure(figsize=(12, 8)) sns.barplot(x='Location', y='count', hue='Category', data=wujing_preferred_categories) plt.title('Preferred Product Categories by Location') plt.xticks(rotation=45) plt.show() # 4.2.4 地区中更偏好的机器ID wujing_machine_preference = wujing_df.groupby(['Location', 'Device ID']).size().reset_index(name='count') wujing_preferred_machines = wujing_machine_preference.loc[wujing_machine_preference.groupby('Location')['count'].idxmax()] plt.figure(figsize=(12, 8)) sns.barplot(x='Location', y='count', hue='Device ID', data=wujing_preferred_machines) plt.title('Preferred Machine IDs by Location') plt.xticks(rotation=45) plt.show() # 5. 自动售货机投放优化建议 # 输出优化建议 print(""" 根据上述分析结果,我们可以提出以下几点投放优化建议: 1. **产品优化**:根据不同位置用户的偏好调整产品种类,增加高需求产品的供应量。 2. **支付方式优化**:根据支付方式偏好,确保在特定位置的机器支持用户常用的支付方式。 3. **机器布局优化**:根据用户偏好和购买习惯,在用户活跃区域增加高偏好机器的投放密度。 4. **促销活动**:在用户偏好较高的地点推出促销活动,提高销量和用户满意度。 以上建议可以根据实际业务情况进一步细化和调整。 """) 根据代码改写如下代码 # 5 生成优化建议 report = "根据分析结果,提出如下优化建议:\n" # 找出销售额低于平均的自动售货机 low_sales_machines = total_sales[total_sales['Total_Sales'] < total_sales['Total_Sales'].mean()]['Machine'].tolist() if low_sales_machines: report += f"- 对于销售额较低的自动售货机 {low_sales_machines},建议重新评估其位置或调整产品组合。\n" # 找出各地点最畅销的产品类别 popular_products_by_location = preference.idxmax(axis=1).to_dict() for location, category in popular_products_by_location.items(): report += f"- 在 {location} 地区,用户更喜欢 {category} 类产品,可以增加这些产品的库存。\n" # 找出各地点最受欢迎的支付方式(只保留数值列) payment_preference_numeric = payment_preference.select_dtypes(include='number') preferred_payment_methods = payment_preference_numeric.idxmax(axis=1).to_dict() for location, method in preferred_payment_methods.items(): report += f"- 在 {location} 地区,用户更倾向于使用 {method} 支付,建议优化该地区的支付设备配置。\n" print(report)
08-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值