zoukankan      html  css  js  c++  java
  • 诚意租房网blog2

     (一)数据库设计部分:

    创建数据库hourse:

    1:关注表

    CREATE TABLE `guanzhu` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `uid` int(11) DEFAULT NULL,

      `hid` int(11) DEFAULT NULL,

      `time` datetime DEFAULT NULL,

      PRIMARY KEY (`id`)

    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

    2:历史表

    CREATE TABLE `history` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `uid` int(11) DEFAULT NULL,

      `uname` varchar(65) DEFAULT NULL,

      `createtime` datetime DEFAULT NULL,

      `hid` int(11) DEFAULT NULL,

      PRIMARY KEY (`id`)

    ) ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8;

    3:房屋信息表

    CREATE TABLE `hourse` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `uname` varchar(255) DEFAULT NULL COMMENT '房东名字',

      `uid` int(11) DEFAULT NULL,

      `image` varchar(255) DEFAULT NULL COMMENT '主视图',

      `image1` varchar(255) DEFAULT NULL,

      `image2` varchar(255) DEFAULT NULL,

      `area` int(11) DEFAULT NULL COMMENT '面积',

      `address` varchar(255) DEFAULT NULL COMMENT '地址',

      `rent_type` int(11) DEFAULT NULL COMMENT '0 日租 1月租',

      `day_price` double DEFAULT NULL COMMENT '日租金',

      `month_price` double DEFAULT NULL COMMENT '月租金',

      `hourse_type` int(66) unsigned DEFAULT NULL COMMENT '1一室一厅2两室一厅3三室一厅',

      `state` int(11) DEFAULT '0' COMMENT '0可申请 1已申请 2已审核 3已入组 4已退房',

      `fabu_state` int(11) DEFAULT '0' COMMENT '0 未审核 自己房屋审核情况',

      `name` varchar(64) DEFAULT NULL COMMENT '名字',

      `xiaoqv` varchar(64) DEFAULT NULL COMMENT '归属小区',

      `introduce` varchar(4000) DEFAULT NULL COMMENT '房子介绍',

      `xqintrodece` varchar(4000) DEFAULT NULL COMMENT '小区介绍',

      `createtime` datetime DEFAULT NULL COMMENT '发布时间',

      `tel` varchar(64) DEFAULT NULL,

      PRIMARY KEY (`id`)

    ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;

    4:订单房屋表

    CREATE TABLE `hourse_order` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `hid` int(11) DEFAULT NULL COMMENT '房子ID',

      `in_time` datetime DEFAULT NULL COMMENT '入住时间',

      `pay_type` int(11) DEFAULT NULL COMMENT '支付方式',

      `out_time` datetime DEFAULT NULL COMMENT '退房时间',

      `price` double DEFAULT NULL COMMENT '总价',

      `state` int(11) DEFAULT NULL COMMENT '申请状态',

      PRIMARY KEY (`id`)

    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    5:留言实体表

    CREATE TABLE `message` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `content` varchar(2000) DEFAULT NULL COMMENT '留言内容',

      `uid` int(11) DEFAULT NULL COMMENT '留言人',

      `hid` int(11) DEFAULT NULL COMMENT '被留言房屋',

      `rank` int(11) DEFAULT NULL COMMENT '评分',

      `time` datetime DEFAULT NULL COMMENT '评论时间',

      `uname` varchar(64) DEFAULT NULL,

      PRIMARY KEY (`id`)

    ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

    6:CREATE TABLE `my_hource` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `hid` int(11) DEFAULT NULL,

      `time` datetime DEFAULT NULL,

      `uid` int(11) DEFAULT NULL,

      PRIMARY KEY (`id`)

    ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

    7:申请表

    CREATE TABLE `shenqing` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `uid` int(11) DEFAULT NULL COMMENT '申请人id',

      `hid` int(11) DEFAULT NULL COMMENT '房子ID',

      `time` datetime DEFAULT NULL COMMENT '申请时间',

      `uname` varchar(64) DEFAULT NULL COMMENT '房东姓名',

      `state` int(11) DEFAULT NULL COMMENT '申请状态',

      `intime` varchar(64) DEFAULT NULL COMMENT '入住时间',

      `renttype` int(11) DEFAULT NULL COMMENT '租住类型',

      `price` double DEFAULT NULL COMMENT '价格',

      `hname` varchar(64) DEFAULT NULL COMMENT '房子姓名',

      `huid` int(11) DEFAULT NULL,

      PRIMARY KEY (`id`)

    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

    8:用户表

    CREATE TABLE `user` (

      `id` int(11) NOT NULL AUTO_INCREMENT,

      `username` varchar(255) DEFAULT NULL,

      `password` varchar(255) DEFAULT NULL,

      `realname` varchar(255) DEFAULT NULL,

      `role` varchar(32) DEFAULT 's' COMMENT 'admin guest',

      `image` varchar(64) DEFAULT NULL COMMENT 'u图片',

      `address` varchar(255) DEFAULT NULL COMMENT '收货地址',

      `phone` varchar(64) DEFAULT NULL,

      `idnumber` varchar(65) DEFAULT NULL COMMENT '身份证号',

      `tel` varchar(64) DEFAULT NULL,

      `sex` int(11) DEFAULT '0',

      `pay` int(11) DEFAULT NULL,

      PRIMARY KEY (`id`)

    ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

    (二)典型代码展示部分:(代码不知道贴什么,所以详细设计与系统实现还是见文档吧)

    import java.util.*;

    import java.util.Map.Entry;

    /**

     * 基于用户的协同过滤推荐算法实现

     * @author Administrator

     */

    public class UserCF {

           /**

            *

            * @param userList 用户喜好集合

            * @param recommendUser 需要的用户

            * @return

            */

           public List<Integer> recoment(List<RecommentUser> userList,Integer recommendUser){

                  List<Sorf> sorfList = new ArrayList<>();

                  int[][] sparseMatrix = new int[userList.size()][userList.size()];//建立用户稀疏矩阵,用于用户相似度计算【相似度矩阵】

                  Map<Integer, Integer> userItemLength = new HashMap<>();//存储每一个用户对应的不同物品总数  eg: A 3

                  Map<Integer, Set<Integer>> itemUserCollection = new HashMap<>();//建立物品到用户的倒排表 eg: a A B

                  Set<Integer> items = new HashSet<>();//辅助存储物品集合

                  Map<Integer, Integer> userID = new HashMap<>();//辅助存储每一个用户的用户ID映射

                  Map<Integer, Integer> idUser = new HashMap<>();//辅助存储每一个ID对应的用户映射

                  System.out.println("Input user--items maping infermation:<eg:A a b d>");

                  for(int i = 0; i < userList.size() ; i++){//依次处理N个用户 输入数据  以空格间隔

                         RecommentUser user = userList.get(i);

                         int uid = userList.get(i).getId();

                         int size = userList.get(i).getLikeList().size();

                         userItemLength.put(uid, size);//eg: A 3

                         userID.put(uid, i);//用户ID与稀疏矩阵建立对应关系

                         idUser.put(i, uid);

                         //建立物品--用户倒排表

                         for(int j = 0; j < size; j ++){

                                if(items.contains(user.getLikeList().get(j))){//如果已经包含对应的物品--用户映射,直接添加对应的用户

                                       itemUserCollection.get(user.getLikeList().get(j)).add(uid);

                                }else{//否则创建对应物品--用户集合映射

                                       items.add(user.getLikeList().get(j));

                                       itemUserCollection.put(user.getLikeList().get(j), new HashSet<Integer>());//创建物品--用户倒排关系

                                       itemUserCollection.get(user.getLikeList().get(j)).add(uid);

                                }

                         }

                  }

                  System.out.println(itemUserCollection.toString());

                  //计算相似度矩阵【稀疏】

                  Set<Entry<Integer, Set<Integer>>> entrySet = itemUserCollection.entrySet();

                  Iterator<Entry<Integer, Set<Integer>>> iterator = entrySet.iterator();

                  while(iterator.hasNext()){

                         Set<Integer> commonUsers = iterator.next().getValue();

                         for (Integer user_u : commonUsers) {

                                for (Integer user_v : commonUsers) {

                                       if(user_u.equals(user_v)){

                                              continue;

                                       }

                                       sparseMatrix[userID.get(user_u)][userID.get(user_v)] += 1;//计算用户u与用户v都有正反馈的物品总数

                                }

                         }

                  }

                  for (int i = 0; i < userList.size(); i++) {

                         System.out.println("用户" + userList.get(i).getId() + ":" + userList.get(i).getLikeList().toString());

                  }

                  //计算用户之间的相似度【余弦相似性】

                  int recommendUserId = userID.get(recommendUser);

                  for (int j = 0;j < sparseMatrix.length; j++) {

                         if(j != recommendUserId){

                                System.out.println(idUser.get(recommendUserId)+"--"+idUser.get(j)+"相似度:"+sparseMatrix[recommendUserId][j]/Math.sqrt(userItemLength.get(idUser.get(recommendUserId))*userItemLength.get(idUser.get(j))));

                         }

                  }

                  //计算指定用户recommendUser的物品推荐度

                  for(Integer item: items){//遍历每一件物品

                         Set<Integer> users = itemUserCollection.get(item);//得到购买当前物品的所有用户集合

                         if(!users.contains(recommendUser)){//如果被推荐用户没有购买当前物品

                                // 则进行推荐度计算

                                double itemRecommendDegree = 0.0;

                                for(Integer user: users){

                                       itemRecommendDegree += sparseMatrix[userID.get(recommendUser)][userID.get(user)]/Math.sqrt(userItemLength.get(recommendUser)*userItemLength.get(user));//推荐度计算

                                }

                                System.out.println("商品"+item+" 对用户 "+recommendUser +"'推荐度:"+itemRecommendDegree);

                                Sorf sorf = new Sorf(item,itemRecommendDegree);

                                sorfList.add(sorf);

                         }

                  }

                  Collections.sort(sorfList);

                  int size = 0;

                  if(sorfList.size() <5){

                         size = sorfList.size();

                  }else {

                         size = 4;

                  }

                  List<Integer> ids = new ArrayList<>();

                  for (int i = 0; i < size; i++) {

                         ids.add(sorfList.get(i).getKey());

                  }

                  return ids;

           }

    }

  • 相关阅读:
    CSS练习
    关于进度模型和进度计划
    信息管理系统/记录管理系统/配置管理系统
    分析技术在PMP中的应用
    渐进明细的几个点
    android手机内的通讯录数据库
    用FileExplorer查看android手机中的数据库
    VCard介绍
    org.apache.http.client.methods.HttpGet 转到定义找不到源代码
    Android : Your APK does not seem to be designed for tablets.
  • 原文地址:https://www.cnblogs.com/April315/p/10920423.html
Copyright © 2011-2022 走看看