基于数据挖掘的旅游推荐APP(三):热门景点模块

        该模块数据来源于百度搜索风云榜之今日风景名胜排行榜(链接),通过调用托管在神箭手云上的API接口可以实现数据的实时抓取,可以参考这里。

        效果图:

                      

        接着上一篇继续说,该模块对应LauchFragment,代码如下:

LaunchFragment.java

public class LaunchFragment extends Fragment {

    private static final String TAG="LaunchFragment";
    private RecyclerView mRecyclerView;
    private List<HotSpotRankItem> mItems= new ArrayList<>(); //这里必须写= new ArrayList<>(),否则可能空指针报错
                        //多线程原因,后台联网下载时,主线程运行,当运行到getItemCount时报错

    public static LaunchFragment newInstance(){
        return new LaunchFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
        new FetchItemsTask().execute();
    }

    @Override
    public View onCreateView(LayoutInflater inflater,  ViewGroup container, Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.fragment_launch,container,false);
        mRecyclerView=(RecyclerView) v.findViewById(R.id.hotspot_recycler_view);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        setupAdapter();
        return v;
    }

    private void setupAdapter() {
        if (isAdded()) {
            //mItems=new BaiDuTopFetchr().fetchItems();//由于多线程运行,需要先判断fragment是否和activity连接
            mRecyclerView.setAdapter(new HotSpotAdapter(mItems));
        }
    }

    private class HotSpotHolder extends RecyclerView.ViewHolder{
        private TextView mRankTextView;
        private TextView mKeywordTextView;
        private TextView mIndexTextView;
        private HotSpotRankItem mHotSpotRankItem;

        public HotSpotHolder(View itemView) {
            super(itemView);
            mRankTextView=(TextView)itemView.findViewById(R.id.hotspot_rank);
            mKeywordTextView=(TextView)itemView.findViewById(R.id.hotspot_keyword);
            mIndexTextView=(TextView)itemView.findViewById(R.id.hotspot_index);
        }

        public void bindHotSpot(HotSpotRankItem hotspot){
            mRankTextView.setText(hotspot.getRank());
            mKeywordTextView.setText(hotspot.getKeyword());
            mIndexTextView.setText("搜索指数:"+hotspot.getIndex());
        }
    }

    private class HotSpotAdapter extends RecyclerView.Adapter<HotSpotHolder>{
        private List<HotSpotRankItem> mHotSpotRankItems;

        public HotSpotAdapter(List<HotSpotRankItem> hotSpotRankItems) {
            mHotSpotRankItems = hotSpotRankItems;
        }

        @Override
        public HotSpotHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view=LayoutInflater.from(getActivity()).inflate(R.layout.list_item_hotspot,parent,false);
            return new HotSpotHolder(view);
        }

        @Override
        public void onBindViewHolder(HotSpotHolder holder, int position) {
            HotSpotRankItem hotspot=mHotSpotRankItems.get(position);
            holder.bindHotSpot(hotspot);
        }

        @Override
        public int getItemCount() {
            return mHotSpotRankItems.size();
        }
    }

    private class FetchItemsTask extends AsyncTask<Void,Void,List<HotSpotRankItem>> {
        @Override
        protected List<HotSpotRankItem> doInBackground(Void... params) {
            Log.i(TAG,"do in back");
            return new BaiDuTopFetchr().fetchItems();
        }

        @Override
        protected void onPostExecute(List<HotSpotRankItem> hotSpotRankItems) {
            Log.i(TAG,"return otems");
            mItems=hotSpotRankItems;
            setupAdapter();
        }
    }
}

        API调用及返回的json数据解析:

BaiDuTopFetchr.java

public class BaiDuTopFetchr {
    private String mAppid="80b574f8abf4224cee648bb060984015";
    private String mHttpUrl = "http://api.shenjian.io/";
    private String mHttpArg = "appid="+mAppid;

    private static final String TAG = "BaiDuTopFetchr";

    public  String request(String httpUrl, String httpArg) {
        BufferedReader reader=null;
        String result=null;
        StringBuffer sbf=new StringBuffer();
        httpUrl=httpUrl+"?"+httpArg;
        try {
            URL url=new URL(httpUrl);
            HttpURLConnection connection=(HttpURLConnection)url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            InputStream is=connection.getInputStream();
            reader=new BufferedReader(new InputStreamReader(is,"UTF-8"));
            String strRead = null;
            while ((strRead = reader.readLine()) != null) {
                sbf.append(strRead);
                sbf.append("\r\n");
            }
            reader.close();
            result = sbf.toString();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public List<HotSpotRankItem> fetchItems() {

        List<HotSpotRankItem> items = new ArrayList<>();

        try {
            String jsonString = request(mHttpUrl,mHttpArg);
            Log.i(TAG, "Received JSON: " + jsonString);
            JSONObject jsonBody = new JSONObject(jsonString);
            parseItems(items, jsonBody);
        } catch (IOException ioe) {
            Log.e(TAG, "Failed to fetch items", ioe);
        } catch (JSONException je) {
            Log.e(TAG, "Failed to parse JSON", je);
        }

        return items;
    }

    private void parseItems(List<HotSpotRankItem> items, JSONObject jsonBody)
            throws IOException, JSONException {

        JSONArray hotSpotJsonArray = jsonBody.getJSONArray("data");

        for (int i = 0; i < hotSpotJsonArray.length(); i++) {
            JSONObject hotSpotJsonObject = hotSpotJsonArray.getJSONObject(i);

            HotSpotRankItem item = new HotSpotRankItem();
            item.setRank(hotSpotJsonObject.getString("rank"));
            item.setKeyword(hotSpotJsonObject.getString("keyword"));
            item.setIndex(hotSpotJsonObject.getString("index"));

            items.add(item);
        }
    }
}

HotSpotRankItem.java

public class HotSpotRankItem {
    private String mRank;
    private String mKeyword;
    private String mIndex;

    public String getRank() {
        return mRank;
    }

    public void setRank(String rank) {
        mRank = rank;
    }

    public String getKeyword() {
        return mKeyword;
    }

    public void setKeyword(String keyword) {
        mKeyword = keyword;
    }

    public String getIndex() {
        return mIndex;
    }

    public void setIndex(String index) {
        mIndex = index;
    }

}

布局文件:

fragment_launch.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/hotspot_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

list_item_hotspot.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

        <TextView
        android:id="@+id/hotspot_rank"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="4dp"/>

        <TextView
        android:id="@+id/hotspot_keyword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="4dp"/>

        <TextView
        android:id="@+id/hotspot_index"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="4dp"/>

</LinearLayout>
源代码在前面博客里。
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于数据挖掘的客户价值预测方法 赵晓煜,黄小原 (东北大学工商管理学院,辽宁沈阳%%"""*) 摘要:提出了一种利用聚类和分类等数据挖掘技术预测客户价值的新方法·通过对客户历 史交易数据的分析,获得能够综合反映老客户忠诚度和价值度的指标·基于该指标对老客户进行 聚类,将老客户划分为若干个不同价值的客户群,即为每个老客户赋予一个价值等级标号·利用朴 素贝叶斯分类方法来预测新客户(或潜在客户)的价值,并依据预测结果来制定相应的重点客户发 展战略·实例验证了该方法的有效性和可行性· 关键词:数据挖掘;客户价值;聚类;朴素贝叶斯分类;预测 中图分类号:D!!* 文献标识码:E 在当前的竞争环境下,企业正在由以产品为 中心转向以客户为中心·为了更有针对性地开展 市场营销活动,企业特别关注如何识别和保留那 些高价值的客户·因此,准确评估和预测客户价 值、正确选择目标市场成为企业能否有效进行客 户关系管理的关键[%]· 随着信息技术的快速发展和企业信息化程度 的日益提高,企业收集、处理和运用客户数据的能 力大大增强,这为进行客户行为的深入分析创造 了良好的条件·近年来,数据挖掘技术被广泛应用 于营销领域,成为了获取客户知识、支持营销决策 的重要手段[!,C]·本文提出了一种基于数据挖掘 的客户价值预测方法,该方法通过对老客户交易 数据的分析来预测新客户的价值水平,从而为企 业制定客户发展战略提供依据· % 基于客户忠诚/价值指标的老客 户聚类 !"! 基于#$%分析计算客户忠诚/价值指标 最近购买时间(/7>70><)、购买频率 (3/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值