1 package info.mikethomas.fahview.v6project.utilities; 2 3 /* 4 * #%L 5 * This file is part of FAHView-v6project. 6 * %% 7 * Copyright (C) 2011 - 2017 Mike Thomas <mikepthomas@outlook.com> 8 * %% 9 * FAHView is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * % 14 * FAHView is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * % 19 * You should have received a copy of the GNU General Public License 20 * along with FAHView. If not, see <http://www.gnu.org/licenses/>. 21 * #L% 22 */ 23 24 import java.io.File; 25 import java.io.FileNotFoundException; 26 import java.util.Scanner; 27 import java.util.logging.Level; 28 import java.util.logging.Logger; 29 30 /** 31 * Class to extract data from Folding@home client log files. 32 * 33 * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a> 34 * @version $Id: $Id 35 */ 36 public class LogReader { 37 private File FAHlogTxt; 38 private final String COMPLETED_REGEX = "\\[(\\d{2,2}):(\\d{2,2}):(\\d{2,2})\\] Completed (\\d{1,}) out of (\\d{1,}) steps ?\\((\\d{1,2})\\%?\\)"; 39 private int logPosition = 0; 40 41 /** 42 * <p>Constructor for LogReader.</p> 43 * 44 * @param location a {@link java.lang.String} object. 45 */ 46 public LogReader(String location) { 47 FAHlogTxt = new File(location + "/FAHLog-Prev.txt"); 48 49 50 // Static Messages 51 // if (line.contains("Edition")) client.setEdition(line); 52 // if (line.contains("Folding@home Client Version")) client.setVersion(line); 53 // if (line.contains("Launch directory: ")) client.setLaunchDirectory(line); 54 // if (line.contains("Service: ") | line.contains("Executable: ")) client.setExecutable(line); 55 // if (line.contains("Arguments: ")) client.setArguments(line); 56 // 57 // // Client Data 58 // if (line.contains("User name: ")) client.setUserName(line); 59 // if (line.contains("User ID: ")) client.setUserID(line); 60 // if (line.contains("Machine ID: ")) client.setMachineID(line); 61 62 // Queue Data 63 //if (line.contains("Working on queue slot")) setLogPosition(line); 64 65 // Work Unit Data 66 //if (line.contains("Project: ")) client.queue.getQueueIndex(logPosition).wuid.setProject(line); 67 //if (line.contains("Protein: ")) client.queue.getQueueIndex(logPosition).wuid.setProtein(line); 68 // [??:??:??] Completed ????? out of ????? steps (??%) 69 // if (Pattern.matches(COMPLETED_REGEX, line)) client.queue.getQueueIndex(logPosition).wuid.setCompleted(line); 70 71 72 // Client 73 // System.out.println(client.getEdition()); 74 // System.out.println(client.getVersion()); 75 // System.out.println(client.getLaunchDirectory()); 76 // System.out.println(client.getExecutable()); 77 // System.out.println(client.getArguments()); 78 // System.out.println(client.getUserName()); 79 // System.out.println(client.getTeamNo()); 80 // System.out.println(client.getUserID()); 81 // System.out.println(client.getMachineID()); 82 83 } 84 85 /** 86 * <p>Setter for the field <code>logPosition</code>.</p> 87 * 88 * @param line a {@link java.lang.String} object. 89 */ 90 private void setLogPosition(String line) { 91 String values[] = line.split(" "); 92 this.logPosition = Integer.parseInt(values[5]); 93 System.out.println(logPosition); 94 } 95 96 /** {@inheritDoc} */ 97 @Override 98 public String toString() { 99 String contents = ""; 100 try { 101 Scanner scan = new Scanner(FAHlogTxt); 102 while (scan.hasNext()) { 103 String line = scan.nextLine(); 104 contents += (line + "\n"); 105 } 106 } 107 catch (FileNotFoundException ex) { 108 Logger.getLogger(LogReader.class.getName()).log(Level.SEVERE, null, ex); 109 } 110 return contents; 111 } 112 }