Untitled
unknown
plain_text
19 days ago
2.1 kB
2
Indexable
Never
package DHW; /* * ** Question ** Imagine system keeping track of customer visiting various pages on their website `somethingfun.com` System creates a log file for each day and each line having something like [customerId, pageId, timestamp] for * each visit of the customer. Given 2 logs files log1 (day-n) and log2(day-y) find loyal customers which show following properties - Visited 2 unique pages - visited the website on each day * * 1,2,2 => userid, pageid, timestamp * * "user1, page1, timestamp\n user2, page1, timestamp\n user3, page2, timestamp" * */ import java.util.*; public class LogAnalyser { public static void main (String[] args) { String logData1 = "user1, page1, day1\n" + "user2, page1, day1\n"+ "user3, page2, day1"; String logData2 = "user1, page1, day2\n" + "user2, page1, day2\n"+ "user3, page2, day2"; LogAnalyser logAnalyser = new LogAnalyser(); logAnalyser.processLogData(logData1, logData2); } public void processLogData(String logData1, String logData2){ //reading lines //split lines(,) String combinedLogs = logData1 + "\n" + logData2; Map<String, Map<String, Set<String>>> userVisitData = new HashMap<>(); String [] logEntries = combinedLogs.split("\n"); for(String entry: logEntries){ String[] parts = entry.split(","); String userId = parts[0]; String pageId = parts[1]; String timestamp = parts[2]; userVisitData.computeIfAbsent(userId, k -> new HashMap<>()); if(userVisitData.get(userId).containsKey(timestamp)){ userVisitData.get(userId).get(timestamp).add(pageId); } else{ userVisitData.get(userId).put(timestamp, ); } } System.out.println(userVisitData.toString()); } // public void List<String> getUsers (int threshold){ // List<String> users = new ArrayList<>(); // //// for() // // } }
Leave a Comment