package com.javaniu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class java牛2012贡献排行版 {

	public static float 总牛币数(int user_id) {
		float 总牛币数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select niu_count from user where status=2";
			if (user_id != 0) {
				sql += " and id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总牛币数 += rs.getInt("niu_count");
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总牛币数;
	}

	public static float 总评论活动数(int user_id) {
		float 总评论活动数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from activity_comment";
			if (user_id != 0) {
				sql += " where user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总评论活动数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总评论活动数;
	}

	public static float 总评论活动博客数(int user_id) {
		float 总评论活动博客数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from activity_blog_comment";
			if (user_id != 0) {
				sql += " where user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总评论活动博客数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总评论活动博客数;
	}

	public static float 总评论代码数(int user_id) {
		float 总评论代码数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from comment_code";
			if (user_id != 0) {
				sql += " where user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总评论代码数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总评论代码数;
	}

	public static float 总评论寻求数(int user_id) {
		float 总评论寻求数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from comment_explore";
			if (user_id != 0) {
				sql += " where user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总评论寻求数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总评论寻求数;
	}

	public static float 总上传代码数(int user_id) {
		float 总上传代码数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from code where status=2";
			if (user_id != 0) {
				sql += " and user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总上传代码数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总上传代码数;
	}

	public static float 总寻求数(int user_id) {
		float 总寻求数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from explore where status=2";
			if (user_id != 0) {
				sql += " and user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总寻求数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总寻求数;
	}

	public static float 总心情数(int user_id) {
		float 总心情数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from mood";
			if (user_id != 0) {
				sql += " where user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总心情数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总心情数;
	}

	public static float 总同求数(int user_id) {
		float 总同求数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from reexplore where status=2";
			if (user_id != 0) {
				sql += " and user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总同求数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总同求数;
	}

	public static float 总下载代码数(int user_id) {
		float 总下载代码数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from user_download";
			if (user_id != 0) {
				sql += " where user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总下载代码数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总下载代码数;
	}

	public static float 总浏览寻求数(int user_id) {
		float 总浏览寻求数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(id) from user_view";
			if (user_id != 0) {
				sql += " where user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总浏览寻求数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总浏览寻求数;
	}

	public static float 总代码被下载数(int user_id) {
		float 总代码被下载数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(ud.id) from user_download ud left join code c on ud.code_id=c.id where c.status=2";
			if (user_id != 0) {
				sql += " and c.user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总代码被下载数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总代码被下载数;
	}

	public static float 总寻求被浏览数(int user_id) {
		float 总寻求被浏览数 = 0;
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select count(uv.id) from user_view uv left join explore e on uv.explore_id=e.id where e.status=2";
			if (user_id != 0) {
				sql += " and e.user_id=" + user_id;
			}
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				总寻求被浏览数 += rs.getInt(1);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 总寻求被浏览数;
	}

	public static List<Integer> 所有用户id() {
		List<Integer> 所有用户id = new ArrayList<Integer>();
		Connection conn = null;

		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select id from user where status=2";
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				所有用户id.add(rs.getInt("id"));
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) { /* ignore close errors */
				}
			}
		}
		return 所有用户id;
	}

	public static void main(String[] args) {
		int 贡献值 = 0;
		float 牛币数 = 0;
		float 总牛币数 = 总牛币数(0);
		if (总牛币数 == 0) {
			总牛币数 = 1;
		}
		float 评论活动数 = 0;
		float 总评论活动数 = 总评论活动数(0);
		if (总评论活动数 == 0) {
			总评论活动数 = 1;
		}
		float 评论活动博客数 = 0;
		float 总评论活动博客数 = 总评论活动博客数(0);
		if (总评论活动博客数 == 0) {
			总评论活动博客数 = 1;
		}
		float 评论代码数 = 0;
		float 总评论代码数 = 总评论代码数(0);
		if (总评论代码数 == 0) {
			总评论代码数 = 1;
		}
		float 评论寻求数 = 0;
		float 总评论寻求数 = 总评论寻求数(0);
		if (总评论寻求数 == 0) {
			总评论寻求数 = 1;
		}
		float 上传代码数 = 0;
		float 总上传代码数 = 总上传代码数(0);
		if (总上传代码数 == 0) {
			总上传代码数 = 1;
		}
		float 寻求数 = 0;
		float 总寻求数 = 总寻求数(0);
		if (总寻求数 == 0) {
			总寻求数 = 1;
		}
		float 心情数 = 0;
		float 总心情数 = 总心情数(0);
		if (总心情数 == 0) {
			总心情数 = 1;
		}
		float 同求数 = 0;
		float 总同求数 = 总同求数(0);
		if (总同求数 == 0) {
			总同求数 = 1;
		}
		float 下载代码数 = 0;
		float 总下载代码数 = 总下载代码数(0);
		if (总下载代码数 == 0) {
			总下载代码数 = 1;
		}
		float 浏览寻求数 = 0;
		float 总浏览寻求数 = 总浏览寻求数(0);
		if (总浏览寻求数 == 0) {
			总浏览寻求数 = 1;
		}
		float 代码被下载数 = 0;
		float 总代码被下载数 = 总代码被下载数(0);
		if (总代码被下载数 == 0) {
			总代码被下载数 = 1;
		}
		float 寻求被浏览数 = 0;
		float 总寻求被浏览数 = 总寻求被浏览数(0);
		if (总寻求被浏览数 == 0) {
			总寻求被浏览数 = 1;
		}
		List<Integer> 所有用户id = 所有用户id();
		Map<String, Integer> ret = new HashMap<String, Integer>();

		int i = 1;
		for (Integer user_id : 所有用户id) {
			牛币数 = 总牛币数(user_id);
			评论活动数 = 总评论活动数(user_id);
			评论活动博客数 = 总评论活动博客数(user_id);
			评论代码数 = 总评论代码数(user_id);
			评论寻求数 = 总评论寻求数(user_id);
			上传代码数 = 总上传代码数(user_id);
			寻求数 = 总寻求数(user_id);
			心情数 = 总心情数(user_id);
			同求数 = 总同求数(user_id);
			下载代码数 = 总下载代码数(user_id);
			浏览寻求数 = 总浏览寻求数(user_id);
			代码被下载数 = 总代码被下载数(user_id);
			寻求被浏览数 = 总寻求被浏览数(user_id);
			贡献值 = (int) (((牛币数 / 总牛币数) + (评论活动数 / 总评论活动数)
					+ (评论活动博客数 / 总评论活动博客数) + (评论代码数 / 总评论代码数)
					+ (评论寻求数 / 总评论寻求数) + (上传代码数 / 总上传代码数) + (寻求数 / 总寻求数)
					+ (心情数 / 总心情数) + (同求数 / 总同求数) + (下载代码数 / 总下载代码数)
					+ (浏览寻求数 / 总浏览寻求数) + (代码被下载数 / 总代码被下载数) * 2 + (寻求被浏览数 / 总寻求被浏览数)) * 100);
			System.out.println("用户" + user_id + "的贡献值" + 贡献值 + "," + (i++)
					+ " in " + 所有用户id.size());
			ret.put(user_id + "", 贡献值);
		}
		ValueComparator bvc = new ValueComparator(ret);
		TreeMap<String, Integer> sortedMap = new TreeMap<String, Integer>(bvc);
		sortedMap.putAll(ret);
		for (String user_id : sortedMap.keySet()) {
			System.out.println("用户" + user_id + "的贡献值" + ret.get(user_id));
		}

	}
}

class ValueComparator implements Comparator<String> {

	Map<String, Integer> base;

	public ValueComparator(Map<String, Integer> base) {
		this.base = base;
	}

	public int compare(String a, String b) {
		if (base.get(a) >= base.get(b)) {
			return -1;
		} else {
			return 1;
		}
	}
}
最近下载更多
branice  LV18 2017年9月5日
mjtljx  LV42 2014年10月1日
AXIN  LV36 2014年2月25日
wgtgt  LV24 2014年2月16日
最近浏览更多
444105047  LV6 2023年11月30日
神龙摆尾无拘束  LV2 2023年3月17日
twedss 2022年6月17日
暂无贡献等级
yangctz  LV24 2022年3月22日
hhhggrt  LV3 2021年4月21日
635969151  LV12 2020年12月24日
joooooo  LV5 2020年12月20日
桌子与灯  LV6 2020年11月18日
Azure1  LV3 2020年8月11日
614404356 2020年7月23日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友