Package cu.ftpd.user.statistics

Examples of cu.ftpd.user.statistics.StatisticsEntry


        sb.append(String.format(format.get(11), user.hasLeech())).append("\r\n");
        sb.append(format.get(12)).append("\r\n");
        sb.append(format.get(13)).append("\r\n");
        sb.append(format.get(14)).append("\r\n");
        // stats
        StatisticsEntry se = ServiceManager.getServices().getUserStatistics().getUserStatistics(user.getUsername(), "default");
        sb.append(String.format(format.get(15), se.get(UserStatistics.ALLUP_FILES), se.get(UserStatistics.ALLDN_FILES))).append("\r\n");
        sb.append(String.format(format.get(16), Formatter.size(se.get(UserStatistics.ALLUP_BYTES)), Formatter.size(se.get(UserStatistics.ALLDN_BYTES)))).append("\r\n");
        sb.append(String.format(format.get(17), Formatter.speed(se.get(UserStatistics.ALLUP_BYTES), se.get(UserStatistics.ALLUP_TIME)), Formatter.speed(se.get(UserStatistics.ALLDN_BYTES), se.get(UserStatistics.ALLDN_TIME)))).append("\r\n");
       
        sb.append(format.get(18)).append("\r\n");
        sb.append(format.get(19)).append("\r\n");
        sb.append(format.get(20)).append("\r\n");
        // groups
View Full Code Here


        long alluptime = 0;
        long alldntime = 0;
        int usersInGroup = 0;
        int usersInGroupWithAllotment = 0;
        int usersInGroupWithLeech = 0;
        StatisticsEntry use;
        List<User> members = new LinkedList<User>();

    for (User user : Sort.users(ServiceManager.getServices().getUserbase().getUsers().values())) {
            if (user.isMemberOfGroup(group.getName())) {
                usersInGroup++;
                if (ServiceManager.getServices().getUserbase().userUsesLeechSlotForGroup(user.getUsername(), group.getName())) {
                    usersInGroupWithLeech++;
                }
                if (ServiceManager.getServices().getUserbase().userUsesAllotmentSlotForGroup(user.getUsername(), group.getName())) {
                    usersInGroupWithAllotment++;
                }
                members.add(user);
                use = ServiceManager.getServices().getUserStatistics().getUserStatistics(user.getUsername(), "default");
                allupbytes += use.get(UserStatistics.ALLUP_BYTES);
                alldnbytes += use.get(UserStatistics.ALLDN_BYTES);
                allupfiles += use.get(UserStatistics.ALLUP_FILES);
                alldnfiles += use.get(UserStatistics.ALLDN_FILES);
                alluptime += use.get(UserStatistics.ALLUP_TIME);
                alldntime += use.get(UserStatistics.ALLDN_TIME);
                // users with leech and allotment need to check if they are using up slots in this group for that
                // NOTE: these are the ONLY places where these methods are used. it seems a bit superflous.
                // they might also be used when listing allotments and leechers (no, then we'll just list the data from the objects, or will we?)
            }
        }
View Full Code Here

                    // flag F | G = UserPermission.CREDITS
                    // flag H = UserPermission.VIEWUSER
                } else if (line.startsWith("ALLUP")) {
                    // _todo: find out the real format for stats
                    // one "set" of values for each section
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.ALLUP_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.ALLUP_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.ALLUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("ALLDN")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.ALLDN_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.ALLDN_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.ALLUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("MNUP")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.MNUP_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.MNUP_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.MNUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("MNDN")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.MNDN_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.MNDN_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.MNUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("WKUP")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.WKUP_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.WKUP_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.WKUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("WKDN")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.WKDN_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.WKDN_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.WKUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("DAYUP")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.DAYUP_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.DAYUP_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.DAYUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("DAYDN")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.DAYDN_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.DAYDN_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.DAYUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("GROUP")) {
                    String[] groupdata = line.substring(5).trim().split(" ", 2);
                    final String group = groupdata[0].trim();
                    user.addGroup(group);
View Full Code Here

    public void upload(String username, String section, long bytes, long time) {}

    public void download(String username, String section, long bytes, long time) {}

    public StatisticsEntry getUserStatistics(String username, String section) {
        return new StatisticsEntry(username, section);
    }
View Full Code Here

      userStatisticsDir.mkdirs();
      if (!userStatisticsDir.isDirectory()) {
            throw new IllegalArgumentException("Could not find dir for user statistics: " + userStatisticsDir.getAbsolutePath() + " (or it is not a directory)");
        } else {
            for (String filename : userStatisticsDir.list()) {
                StatisticsEntry se = loadUserStatistics(filename);
                if (se != null) { // since we can return null, we can do a simple .isFile() check in the method
                    statistics.put(filename, se);
                }
            }
        }
View Full Code Here

            }
        }
    }

    public void upload(String username, String section, long bytes, long time) {
        StatisticsEntry us = getUserStatistics(username, section);
        us.upload(bytes, time);
        store(us);

        if (!"default".equals(section)) {
            // always add the data to the default section as well, since that keeps track of ALL the statistics
            us = getUserStatistics(username, "default");
            us.upload(bytes, time);
            store(us);
        }
    }
View Full Code Here

            store(us);
        }
    }

    public void download(String username, String section, long bytes, long time) {
        StatisticsEntry us = getUserStatistics(username, section);
        us.download(bytes, time);
        store(us);

        if (!"default".equals(section)) {
            // always add the data to the default section as well, since that keeps track of ALL the statistics
            us = getUserStatistics(username, "default");
            us.download(bytes, time);
            store(us);
        }
    }
View Full Code Here

            // some weird file, skip it (this also means that usernames or sections cannon contain periods)
            return null;
            // _todo: let it be possible for sections to contain periods, so this check must be done in a different manner
            // sections can no longer contain periods
        }
        StatisticsEntry us = new StatisticsEntry(s[0], s[1]);
        //long start = System.currentTimeMillis();
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(new FileInputStream(statfile)));
            String line = in.readLine();
            try {
                us.setLastUpdate(Long.parseLong(line));
                line = in.readLine();
            } catch (NumberFormatException e) {
                // do nothing
                // we get this error if we convert from old-style files that did not have this date at the top
            }
            line = line.substring(1, line.length() - 1); // remove the wrapping "[" and "]"
            String[] statline = line.split(",\\s+");
            for (int i = 0; i < statline.length; i++) {
                try {
                    us.set(i, Long.parseLong(statline[i]));
                } catch (NumberFormatException e) {
                    System.err.println("Found bad data in user statistics file: " + statline[i] + " for user: " + filename);
                }
            }
            statistics.put(filename, us);
View Full Code Here

        // _todo: handle the case of the default section
        // no problem, the default section is named "default", so there will always be a name
        // _todo: we must handle this for extracting statistics as well, also, when we add stuff to a section, we also always need to add it to the default section
        // done (see download() and upload())
        //System.out.println("requesting statistics entry: " + username + "." + section);
        StatisticsEntry us = statistics.get(username + '.' + section);
        if (us == null) {
            //System.out.println("entry not found, creating...");
            us = new StatisticsEntry(username, section);
            statistics.put(username + '.' + section, us);
        }
        return us;
    }
View Full Code Here

        }
        HashMap<String, StatisticsEntry> groupStats = new HashMap<String, StatisticsEntry>();
        for (User user : ServiceManager.getServices().getUserbase().getUsers().values()) {
            // note: this only lists groups that have members in them. otherwise they won't have any stats anyway
            for (String group : user.getGroups()) {
                StatisticsEntry stat = groupStats.get(group);
                if (stat == null) {
                    stat = new StatisticsEntry(group, section);
                    groupStats.put(group, stat);
                }
                // _todo: support using sections here (maybe in the future)
                // not yet, too much work, and nobody will use if. if the users want it, I will add it.
                stat.set(UserStatistics.ALLUP_BYTES, (stat.get(UserStatistics.ALLUP_BYTES) + getUserStatistics(user.getUsername(), section).get(UserStatistics.ALLUP_BYTES)));
                stat.set(UserStatistics.ALLDN_BYTES, (stat.get(UserStatistics.ALLDN_BYTES) + getUserStatistics(user.getUsername(), section).get(UserStatistics.ALLDN_BYTES)));
                stat.set(UserStatistics.MNUP_BYTES, (stat.get(UserStatistics.MNUP_BYTES) + getUserStatistics(user.getUsername(), section).get(UserStatistics.MNUP_BYTES)));
                stat.set(UserStatistics.MNDN_BYTES, (stat.get(UserStatistics.MNDN_BYTES) + getUserStatistics(user.getUsername(), section).get(UserStatistics.MNDN_BYTES)));
                stat.set(UserStatistics.WKUP_BYTES, (stat.get(UserStatistics.WKUP_BYTES) + getUserStatistics(user.getUsername(), section).get(UserStatistics.WKUP_BYTES)));
                stat.set(UserStatistics.WKDN_BYTES, (stat.get(UserStatistics.WKDN_BYTES) + getUserStatistics(user.getUsername(), section).get(UserStatistics.WKDN_BYTES)));
                stat.set(UserStatistics.DAYUP_BYTES, (stat.get(UserStatistics.DAYUP_BYTES) + getUserStatistics(user.getUsername(), section).get(UserStatistics.DAYUP_BYTES)));
                stat.set(UserStatistics.DAYDN_BYTES, (stat.get(UserStatistics.DAYDN_BYTES) + getUserStatistics(user.getUsername(), section).get(UserStatistics.DAYDN_BYTES)));
            }
        }
        return groupStats;
    }
View Full Code Here

TOP

Related Classes of cu.ftpd.user.statistics.StatisticsEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.