Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Created July 25, 2011 20:24
Show Gist options
  • Save pokutuna/1105098 to your computer and use it in GitHub Desktop.
Save pokutuna/1105098 to your computer and use it in GitHub Desktop.
import java.util.*;
import com.pokutuna.lifelog.db.dao.SensingDAOForJava;
import com.pokutuna.lifelog.db.model.SensingModel.*;
import com.pokutuna.lifelog.util.DateTime;
public class MinuteSeparateSample {
SensingDAOForJava sdao = new SensingDAOForJava("jdbc:sqlite:sensing.db");
Map<String, Set<String>> noRepetition = new TreeMap<String, Set<String>>();
//1分区間の開始時間と、その区間内で検出されたアドレスの集合のハッシュ
public MinuteSeparateSample(String start, String end){
DateTime cursorDt = DateTime.format(start); //開始時刻をDateTimeに
while(cursorDt.asString().compareTo(end) < 0){ //文字列比較するにはcompareTo
System.out.println(cursorDt.asString());
List<DetectedRecord> detects = sdao.detectedIn(cursorDt.asString(), cursorDt.fromNow(0, 0, 0, 0, 0, 59).asString()); //始点と、始点の59秒後をDateTime#fromNowで作ってる
Set<String> addresses = new HashSet<String>(); //アドレス入れとく用セット
for(DetectedRecord d : detects) {
addresses.add(d.address()); //レコードからアドレスをセットに入れる
}
noRepetition.put(cursorDt.asString(), addresses); //開始時刻とアドレスセットをハッシュに入れる
cursorDt = cursorDt.fromNow(0, 0, 0, 0, 1, 0); //時刻を1分後に
}
}
public static void main(String[] args) {
MinuteSeparateSample mss = new MinuteSeparateSample("2011-06-01 12:00:00", "2011-06-01 13:00:00");
for(Map.Entry<String, Set<String>> entry : mss.noRepetition.entrySet()) {
System.out.println(entry);
}
}
}
2011-06-01 12:00:00
2011-06-01 12:01:00
2011-06-01 12:02:00
2011-06-01 12:03:00
2011-06-01 12:04:00
2011-06-01 12:05:00
2011-06-01 12:06:00
2011-06-01 12:07:00
2011-06-01 12:08:00
2011-06-01 12:09:00
2011-06-01 12:10:00
2011-06-01 12:11:00
2011-06-01 12:12:00
2011-06-01 12:13:00
2011-06-01 12:14:00
2011-06-01 12:15:00
2011-06-01 12:16:00
2011-06-01 12:17:00
2011-06-01 12:18:00
2011-06-01 12:19:00
2011-06-01 12:20:00
2011-06-01 12:21:00
2011-06-01 12:22:00
2011-06-01 12:23:00
2011-06-01 12:24:00
2011-06-01 12:25:00
2011-06-01 12:26:00
2011-06-01 12:27:00
2011-06-01 12:28:00
2011-06-01 12:29:00
2011-06-01 12:30:00
2011-06-01 12:31:00
2011-06-01 12:32:00
2011-06-01 12:33:00
2011-06-01 12:34:00
2011-06-01 12:35:00
2011-06-01 12:36:00
2011-06-01 12:37:00
2011-06-01 12:38:00
2011-06-01 12:39:00
2011-06-01 12:40:00
2011-06-01 12:41:00
2011-06-01 12:42:00
2011-06-01 12:43:00
2011-06-01 12:44:00
2011-06-01 12:45:00
2011-06-01 12:46:00
2011-06-01 12:47:00
2011-06-01 12:48:00
2011-06-01 12:49:00
2011-06-01 12:50:00
2011-06-01 12:51:00
2011-06-01 12:52:00
2011-06-01 12:53:00
2011-06-01 12:54:00
2011-06-01 12:55:00
2011-06-01 12:56:00
2011-06-01 12:57:00
2011-06-01 12:58:00
2011-06-01 12:59:00
2011-06-01 12:59:00=[]
2011-06-01 12:03:00=[06:24:A5:C5:C4:89, 00:24:A5:C5:C4:89, 00:18:84:89:A9:75, 00:1D:73:7B:6D:EB]
2011-06-01 12:47:00=[]
2011-06-01 12:44:00=[]
2011-06-01 12:27:00=[]
2011-06-01 12:29:00=[00:1D:73:C5:8D:EA]
2011-06-01 12:41:00=[]
2011-06-01 12:20:00=[]
2011-06-01 12:40:00=[00:18:84:7E:C2:39]
2011-06-01 12:57:00=[BC:B1:81:59:79:C0]
2011-06-01 12:00:00=[00:18:84:89:A9:75, 00:18:84:89:A9:74]
2011-06-01 12:22:00=[]
2011-06-01 12:18:00=[]
2011-06-01 12:42:00=[]
2011-06-01 12:34:00=[0A:25:5C:4C:3B:51, 0E:25:5C:4C:3B:51, BC:B1:81:C4:10:31, 06:25:5C:4C:3B:51]
2011-06-01 12:02:00=[00:18:84:89:A9:75, 00:18:84:89:A9:74, 00:1D:73:6D:3A:A0]
2011-06-01 12:11:00=[]
2011-06-01 12:12:00=[]
2011-06-01 12:43:00=[]
2011-06-01 12:48:00=[]
2011-06-01 12:04:00=[06:24:A5:C5:C4:89, 00:24:A5:C5:C4:89, 00:1D:73:7B:6D:EB]
2011-06-01 12:01:00=[00:18:84:89:A9:75, 00:18:84:89:A9:74]
2011-06-01 12:46:00=[]
2011-06-01 12:49:00=[]
2011-06-01 12:09:00=[]
2011-06-01 12:50:00=[]
2011-06-01 12:07:00=[]
2011-06-01 12:28:00=[00:1D:73:C5:8D:EA]
2011-06-01 12:21:00=[]
2011-06-01 12:15:00=[]
2011-06-01 12:32:00=[]
2011-06-01 12:56:00=[BC:B1:81:59:79:C0]
2011-06-01 12:06:00=[]
2011-06-01 12:14:00=[]
2011-06-01 12:35:00=[]
2011-06-01 12:38:00=[]
2011-06-01 12:08:00=[]
2011-06-01 12:39:00=[]
2011-06-01 12:45:00=[]
2011-06-01 12:37:00=[]
2011-06-01 12:58:00=[]
2011-06-01 12:23:00=[]
2011-06-01 12:19:00=[00:1C:EE:78:9B:A1, 02:2E:AE:97:CF:96]
2011-06-01 12:13:00=[]
2011-06-01 12:53:00=[00:1F:C4:1C:1A:D6]
2011-06-01 12:54:00=[00:1F:C4:1C:1A:D6, 00:22:F3:02:AE:A1]
2011-06-01 12:51:00=[]
2011-06-01 12:52:00=[]
2011-06-01 12:05:00=[06:24:A5:C5:C4:89, 00:24:A5:C5:C4:89]
2011-06-01 12:24:00=[]
2011-06-01 12:30:00=[00:1D:73:C5:8D:EA]
2011-06-01 12:17:00=[]
2011-06-01 12:31:00=[]
2011-06-01 12:10:00=[]
2011-06-01 12:55:00=[00:1F:C4:1C:1A:D6, 00:22:F3:02:AE:A1, BC:B1:81:59:79:C0]
2011-06-01 12:25:00=[]
2011-06-01 12:36:00=[]
2011-06-01 12:16:00=[]
2011-06-01 12:26:00=[]
2011-06-01 12:33:00=[0A:25:5C:4C:3B:51, 06:25:5C:4C:3B:51]
@pokutuna
Copy link
Author

TIME (ms) BEGIN (total = 47443) Tue Jul 26 06:26:22 2011
rank self accum count trace method
1 62.91% 62.91% 120 315633 org.sqlite.DB.execute
2 0.75% 63.66% 748 305726 java.lang.ClassLoader.defineClassCond
3 0.42% 64.08% 13576 300786 java.util.HashMap.get
4 0.38% 64.45% 23640 312980 scala.collection.mutable.StringBuilder.charAt
5 0.38% 64.83% 13653 300792 sun.misc.URLClassPath$JarLoader.getResource
6 0.32% 65.15% 1398 300252 java.lang.StringCoding.scale
7 0.31% 65.46% 14377 300771 java.util.ArrayList.get
8 0.31% 65.77% 8640 312170 org.scalaquery.ql.basic.BasicSQLUtils$$anonfun$quoteIdentifier$1.apply
9 0.29% 66.06% 1685 304565 sun.security.provider.ByteArrayAccess.b2iBig64
10 0.29% 66.35% 15101 300772 sun.misc.URLClassPath.getLoader
11 0.27% 66.63% 1560 312099 scala.collection.mutable.StringBuilder.
12 0.26% 66.89% 1464 300724 java.net.URLStreamHandler.parseURL
13 0.26% 67.15% 13792 300774 java.util.zip.ZipFile.getEntry
14 0.25% 67.40% 120 315717 org.sqlite.DB.close
15 0.24% 67.64% 23640 312979 java.lang.StringBuilder.charAt
16 0.24% 67.88% 6734 300790 sun.misc.JarIndex.get
17 0.23% 68.10% 26992 304564 java.lang.Integer.reverseBytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment