周小娜 9 months ago
parent 584f1db48f
commit 5c011ce1b0

@ -4,8 +4,13 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="a7505764-040b-48e2-b2fc-8c5b579e595f" name="Default" comment=""> <list default="true" id="a7505764-040b-48e2-b2fc-8c5b579e595f" name="Default" comment="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成11">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/cn/edu/hust/conf/ConfigurationManager.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cn/edu/hust/conf/ConfigurationManager.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/cn/edu/hust/constant/Constants.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cn/edu/hust/constant/Constants.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/cn/edu/hust/util/DateUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cn/edu/hust/util/DateUtils.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/cn/edu/hust/util/DateUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cn/edu/hust/util/DateUtils.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/cn/edu/hust/conf/ConfigurationManagerTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/cn/edu/hust/conf/ConfigurationManagerTest.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -401,6 +406,7 @@
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="SvnConfiguration"> <component name="SvnConfiguration">
<configuration /> <configuration />
</component> </component>
@ -420,7 +426,7 @@
<workItem from="1529845795654" duration="7752000" /> <workItem from="1529845795654" duration="7752000" />
<workItem from="1529887211212" duration="6851000" /> <workItem from="1529887211212" duration="6851000" />
<workItem from="1529994772485" duration="146000" /> <workItem from="1529994772485" duration="146000" />
<workItem from="1734352117490" duration="375000" /> <workItem from="1734352117490" duration="5045000" />
</task> </task>
<task id="LOCAL-00001" summary="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成"> <task id="LOCAL-00001" summary="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成">
<created>1529592741848</created> <created>1529592741848</created>
@ -436,7 +442,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1529593229553</updated> <updated>1529593229553</updated>
</task> </task>
<option name="localTasksCounter" value="3" /> <task id="LOCAL-00003" summary="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成11">
<created>1734352510160</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1734352510160</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers /> <servers />
</component> </component>
<component name="TestHistory"> <component name="TestHistory">
@ -546,30 +559,17 @@
<map> <map>
<entry key="MAIN"> <entry key="MAIN">
<value> <value>
<State> <State />
<option name="RECENTLY_FILTERED_USER_GROUPS">
<collection />
</option>
<option name="RECENTLY_FILTERED_BRANCH_GROUPS">
<collection />
</option>
<option name="COLUMN_ORDER">
<list>
<option value="0" />
<option value="1" />
<option value="2" />
<option value="3" />
</list>
</option>
</State>
</value> </value>
</entry> </entry>
</map> </map>
</option> </option>
<option name="oldMeFiltersMigrated" value="true" />
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成" /> <MESSAGE value="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成" />
<option name="LAST_COMMIT_MESSAGE" value="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成" /> <MESSAGE value="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成11" />
<option name="LAST_COMMIT_MESSAGE" value="1.环境搭建完成&#10;2.相关的工具类编写完成&#10;3.配置文件管理类编写完成11" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/main/java/cn/edu/hust/conf/ConfigurationManager.java"> <entry file="file://$PROJECT_DIR$/src/main/java/cn/edu/hust/conf/ConfigurationManager.java">

@ -79,6 +79,12 @@
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

@ -1,75 +1,83 @@
package cn.edu.hust.conf; package cn.edu.hust.conf;//包
//
import java.io.InputStream; import java.io.InputStream;//申明
import java.util.Properties; //
import java.util.Properties;//申明
/** //
* //
* :propertieskey/value //配置文件管理类
*/ //主要的功能:从特定的properties文件中读取相应的key/value
public class ConfigurationManager { //
private static Properties prop=new Properties(); public class ConfigurationManager { //
// 创建一个静态的Properties对象用于存储从配置文件中读取的配置信息
/** private static Properties prop = new Properties();// 创建一个静态的Properties对象用于存储从配置文件中读取的配置信息
* //
*/ //
static{ // 通过静态代码块加载配置文件
try //
{ static { //ha
//通过类的加载器读取配置文件 try { //dd
InputStream is=ConfigurationManager.class.getClassLoader().getResourceAsStream("conf.properties"); // 通过类的加载器读取名为"conf.properties"的配置文件
//加载配置文件 InputStream is = ConfigurationManager.class.getClassLoader().getResourceAsStream("conf.properties");//加载
prop.load(is); // 加载配置文件到Properties对象中
}catch(Exception e) prop.load(is);//加载
{ } catch (Exception e)//kuaizai
e.printStackTrace(); // 捕获加载文件时的异常并打印错误堆栈信息
} e.printStackTrace();//kuaizai
} }//对象
} //
/** //编写过程
* keyvalue //编写过程
* @param key //
* @return //通过指定的key获取value
*/ // @param key 配置项的key
public static String getProperty(String key) //@return 返回与key对应的value如果没有则返回null
{ //
return prop.getProperty(key); public static String getProperty(String key) { //
} // 使用Properties对象的getProperty方法获取指定key的值
return prop.getProperty(key); //
/** } //
* //
* @param key //
* @return // 获取整数变量
*/ // @param key 配置项的key
public static Integer getInteger(String key) // @return 返回与key对应的整数值如果转换失败则返回默认值0
{ //
String value=getProperty(key); public static Integer getInteger(String key) { //加载
try // 获取key对应的字符串值
{ String value = getProperty(key);//
Integer result=Integer.valueOf(value); //
return result; try { //
} // 尝试将字符串值转换为整数
catch (Exception e) Integer result = Integer.valueOf(value);//
{ //
return result; //输出结果
e.printStackTrace(); //
} } catch (Exception e) { //catch
return 0; // 捕获转换时的异常并打印错误堆栈信息
} e.printStackTrace(); //e
//
/** }//
* // 如果转换失败返回默认值0
* @param key return 0; //返回值
* @return } //
*/ //
public static Boolean getBoolean(String key) //
{ //获取布尔型
String value=getProperty(key); // @param key 配置项的key
if("false".equals(value)) // @return 返回与key对应的布尔值如果值为"false"则返回false其他情况返回true
{ //
return false; public static Boolean getBoolean(String key) { //
} // 获取key对应的字符串值
return true; String value = getProperty(key); //string
} // 如果值为"false"不区分大小写则返回false
if ("false".equals(value)) { //错误
} //返回值
return false; //返回错误结果
} //
// 默认返回true
return true; //返回正确
}//
//
}//
//完成

@ -1,64 +1,128 @@
package cn.edu.hust.constant; //开始
package cn.edu.hust.constant;//申明
public class Constants { //
/** public class Constants { //
* //
*/ //
public static final String JDBC_DRIVER="jdbc.driver"; // 项目配置常量
public static final String JDBC_URL="jdbc.url"; //这些常量用于存储数据库连接的配置信息
public static final String JDBC_USERNAME="jdbc.username"; //
public static final String JDBC_PSSWORD="jdbc.password"; public static final String JDBC_DRIVER="jdbc.driver"; // JDBC驱动类
public static final String JDBC_ACTIVE="jdbc.active"; //
public static final String JDBC_URL="jdbc.url"; // 数据库连接URL
/** //
* Spark public static final String JDBC_USERNAME="jdbc.username"; // 数据库用户名
*/ //
public static final String APP_NAME_SESSION="UserVisitAnalyze"; public static final String JDBC_PSSWORD="jdbc.password"; // 数据库密码
public static final String SPARK_LOCAL="spark_local"; //
public static final String FIELD_SESSIONID="sessionId"; public static final String JDBC_ACTIVE="jdbc.active"; // 数据库连接是否活跃
public static final String FIELD_SERACH_KEYWORDS="searchKeywords"; //
public static final String FIELD_CLICK_CATEGORYIDS="clickCategoryIds"; //
public static final String FIELD_AGE="age"; //
public static final String FIELD_CITY="city"; //Spark作业相关常量
public static final String FIELD_SEX="sex"; // 这些常量用于存储Spark作业相关的配置信息、字段名等
public static final String FIELD_PROFESSIONAL="professional"; //
public static final String FIELD_VISIT_LENGTH="visitLength"; public static final String APP_NAME_SESSION="UserVisitAnalyze"; // Spark应用名称用于标识作业
public static final String FIELD_STEP_LENGTH="stepLength"; //
public static final String FIELD_START_TIME="startTime"; public static final String SPARK_LOCAL="spark_local"; // Spark本地模式的配置标识
public static final String FIELD_CATEGORY_ID="categoryId"; //
public static final String FIELD_CLICK_CATEGORY="categoryId"; public static final String FIELD_SESSIONID="sessionId"; // 用户会话ID字段名
public static final String FIELD_ORDER_CATEGORY="clickCategory"; //
public static final String FIELD_PAY_CATEGORY="orderCategory"; public static final String FIELD_SERACH_KEYWORDS="searchKeywords"; // 搜索关键词字段名
//
/** public static final String FIELD_CLICK_CATEGORYIDS="clickCategoryIds"; // 点击的分类ID字段名
* Spark //
*/ public static final String FIELD_AGE="age"; // 用户年龄字段名
public static final String PARAM_STARTTIME ="startDate"; //
public static final String PARAM_ENDTIME ="endDate"; public static final String FIELD_CITY="city"; // 用户所在城市字段名
public static final String PARAM_STARTAGE ="startAge"; //
public static final String PARAM_ENDAGE ="endAge"; public static final String FIELD_SEX="sex"; // 用户性别字段名
public static final String PARAM_PROFESSONALS ="professionals"; //
public static final String PARAM_CIYTIES ="cities"; public static final String FIELD_PROFESSIONAL="professional"; // 用户职业字段名
public static final String PARAM_SEX ="sex"; //
public static final String PARAM_SERACH_KEYWORDS="searchKeywords"; public static final String FIELD_VISIT_LENGTH="visitLength"; // 访问时长字段名
public static final String PARAM_CLICK_CATEGORYIDS="clickCategoryIds"; //
public static final String FIELD_STEP_LENGTH="stepLength"; // 访问步长字段名
public static final String SESSION_COUNT = "session_count"; //
public static final String TIME_PERIOD_1s_3s = "1s_3s"; public static final String FIELD_START_TIME="startTime"; // 会话开始时间字段名
public static final String TIME_PERIOD_4s_6s = "4s_6s"; //
public static final String TIME_PERIOD_7s_9s = "7s_9s"; public static final String FIELD_CATEGORY_ID="categoryId"; // 分类ID字段名
public static final String TIME_PERIOD_10s_30s = "10s_30s"; //
public static final String TIME_PERIOD_30s_60s = "30s_60s"; public static final String FIELD_CLICK_CATEGORY="categoryId"; // 点击的分类字段名
public static final String TIME_PERIOD_1m_3m = "1m_3m"; //
public static final String TIME_PERIOD_3m_10m = "3m_10m"; public static final String FIELD_ORDER_CATEGORY="clickCategory"; // 订单分类字段名
public static final String TIME_PERIOD_10m_30m = "10m_30m"; //
public static final String TIME_PERIOD_30m = "30m"; public static final String FIELD_PAY_CATEGORY="orderCategory"; // 支付分类字段名
//
public static final String STEP_PERIOD_1_3 = "1_3"; //
public static final String STEP_PERIOD_4_6 = "4_6"; // Spark任务相关参数常量
public static final String STEP_PERIOD_7_9 = "7_9"; // 这些常量用于存储Spark任务中的参数名称
public static final String STEP_PERIOD_10_30 = "10_30"; //
public static final String STEP_PERIOD_30_60 = "30_60"; public static final String PARAM_STARTTIME ="startDate"; // 起始日期参数
public static final String STEP_PERIOD_60 = "60"; //
public static final String PARAM_ENDTIME ="endDate"; // 结束日期参数
} //
public static final String PARAM_STARTAGE ="startAge"; // 起始年龄参数
//
public static final String PARAM_ENDAGE ="endAge"; // 结束年龄参数
//
public static final String PARAM_PROFESSONALS ="professionals"; // 专业参数
//
public static final String PARAM_CIYTIES ="cities"; // 城市参数
//
public static final String PARAM_SEX ="sex"; // 性别参数
//
public static final String PARAM_SERACH_KEYWORDS="searchKeywords"; // 搜索关键词参数
//
public static final String PARAM_CLICK_CATEGORYIDS="clickCategoryIds"; // 点击的分类ID参数
//
//
//
// 会话统计相关常量
//用于会话时长或访问步数的统计分类
//
public static final String SESSION_COUNT = "session_count"; // 会话统计
//
//
//
// 用户访问时长时间段常量
//用于标识用户访问时长的各个时间段
//
public static final String TIME_PERIOD_1s_3s = "1s_3s"; // 1秒到3秒的时长
//
public static final String TIME_PERIOD_4s_6s = "4s_6s"; // 4秒到6秒的时长
//
public static final String TIME_PERIOD_7s_9s = "7s_9s"; // 7秒到9秒的时长
//
public static final String TIME_PERIOD_10s_30s = "10s_30s"; // 10秒到30秒的时长
//
public static final String TIME_PERIOD_30s_60s = "30s_60s"; // 30秒到60秒的时长
//
public static final String TIME_PERIOD_1m_3m = "1m_3m"; // 1分钟到3分钟的时长
//
public static final String TIME_PERIOD_3m_10m = "3m_10m"; // 3分钟到10分钟的时长
//
public static final String TIME_PERIOD_10m_30m = "10m_30m"; // 10分钟到30分钟的时长
//
public static final String TIME_PERIOD_30m = "30m"; // 超过30分钟的时长
//
//
//
// 用户访问步数时间段常量
//用于标识用户的访问步数区间
//
public static final String STEP_PERIOD_1_3 = "1_3"; // 1步到3步的访问
//
public static final String STEP_PERIOD_4_6 = "4_6"; // 4步到6步的访问
//
public static final String STEP_PERIOD_7_9 = "7_9"; // 7步到9步的访问
//
public static final String STEP_PERIOD_10_30 = "10_30"; // 10步到30步的访问
//
public static final String STEP_PERIOD_30_60 = "30_60"; // 30步到60步的访问
//
public static final String STEP_PERIOD_60 = "60"; // 超过60步的访问
//
//
}//返回
//完成

@ -7,7 +7,7 @@ import java.util.Date;
/** /**
* *
* @author Administrator111 * @author Administrator111222
* *
*/ */
public class DateUtils { public class DateUtils {

@ -1,15 +1,17 @@
package cn.edu.hust.conf; //开始
package cn.edu.hust.conf; // 导入包:配置管理相关的类
//
import org.junit.Test; import org.junit.Test; // 导入JUnit的Test注解用于标识测试方法
//
public class ConfigurationManagerTest { public class ConfigurationManagerTest { // 定义测试类测试ConfigurationManager类的功能
/** //
* //测试配置文件管理类 // 方法注释,表示该方法用于测试配置文件管理类
*/ //
@Test @Test // 使用JUnit的Test注解表示该方法为一个测试方法
public void getMethod() //
{ public void getMethod() // 定义一个测试方法
System.out.println(ConfigurationManager.getProperty("key1")); { //
} System.out.println(ConfigurationManager.getProperty("key1")); // 打印从ConfigurationManager获取key1对应的属性值
} }//
}//
//完成

Loading…
Cancel
Save