Skip to content

Commit

Permalink
Add syslog session extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
caesar0301 committed Dec 10, 2015
1 parent 0da83ba commit 6063442
Show file tree
Hide file tree
Showing 6 changed files with 1,730 additions and 651 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
* Given a AP name string, this function return the description of the building.
* Specifically for AP name, both full name string (the default mode, e.g.
* BYGTSG-4F-01) and building name (e.g. BYGTSG) can be used.
*
* If only building name is given, you can save processing time to declare this
* method with @full_apname param. But for accuracy, the full AP name is preferred.
*
* To update the database, visit
* https://github.com/caesar0301/omnilab-misc/tree/master/DBs/apmap
*
* @author chenxm
*/
public class APToBuilding {
private static final String AP_BUILDING_DATABASE = "/APNamesUTF8.yaml";

private static final String AP_BUILDING_DATABASE = "/apnames-utf8.yaml";
private Map<String, Map<String, String>> APNameDB;
private boolean full_apname = true;
private Map<String, String> APBN_RealBN_Cache = new HashMap<String, String>();
Expand All @@ -35,6 +40,7 @@ public APToBuilding(boolean full_apname){
@SuppressWarnings("unchecked")
public APToBuilding(InputStream APDBYAML, boolean full_apname) {
this.full_apname = full_apname;

// Load yaml database
Yaml yaml = new Yaml(new SafeConstructor());
Map<String,Object> regexConfig = (Map<String,Object>) yaml.load(APDBYAML);
Expand All @@ -43,6 +49,7 @@ public APToBuilding(InputStream APDBYAML, boolean full_apname) {

public List<String> parse(String APName){
List<String> result = null;

if ( APName == null )
return result;

Expand All @@ -58,19 +65,23 @@ public List<String> parse(String APName){
if ( APBN_RealBN_Cache.containsKey(buildName) ) { // Cache hit
String cacheRealBN = APBN_RealBN_Cache.get(buildName);
result = getBuildInfo(cacheRealBN);
} else { // Cache miss
} else {

// Cache miss
if ( APNameDB.containsKey(buildName)) {
result = getBuildInfo(buildName);
APBN_RealBN_Cache.put(buildName, buildName);
} else {
// Worst case; try to find its longest matched building name
String realBuildName = null;

for ( String BN : APNameDB.keySet())
if ( buildName.contains(BN) )
if ( realBuildName == null )
realBuildName = BN;
else if ( BN.length() > realBuildName.length() )
realBuildName = BN; // Get the longest match

if ( realBuildName != null ){
result = getBuildInfo(realBuildName);
// Cache the real building name
Expand All @@ -79,19 +90,26 @@ else if ( BN.length() > realBuildName.length() )
}
}
} else { // Given build name, skip cache actions

if ( APNameDB.containsKey(APName) ) // Have item
result = getBuildInfo(APName);

}

return result;
}

private List<String> getBuildInfo(String realBuildName){

List info = new LinkedList<String>();
Map<String, String> buildInfo = APNameDB.get(realBuildName);
info.add(buildInfo.get("dsp"));
info.add(buildInfo.get("typ"));
info.add(buildInfo.get("usr"));

info.add(buildInfo.get("name"));
info.add(buildInfo.get("type"));
info.add(buildInfo.get("user"));
info.add(buildInfo.get("lat"));
info.add(buildInfo.get("lon"));

return info;
}
}
Loading

0 comments on commit 6063442

Please sign in to comment.