<commit_before>import 'dart:io';

import 'package:logging/logging.dart';
import 'package:logging_handlers/server_logging_handlers.dart';
import 'package:rpc/rpc.dart';
import 'package:mongo_dart/mongo_dart.dart';

const String _API_PREFIX = '/api';
final ApiServer _apiServer =
    new ApiServer(apiPrefix: _API_PREFIX, prettyPrint: true);

main() async {
  // Add a simple log handler to log information to a server side file.
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen(new SyncFileLoggingHandler('hits.log'));
  if (stdout.hasTerminal) {
    Logger.root.onRecord.listen(new LogPrintHandler());
  }

  _apiServer.addApi(new Stumble());
  _apiServer.enableDiscoveryApi();

  HttpServer server = await HttpServer.bind(InternetAddress.ANY_IP_V4, 8080);
  server.listen(_apiServer.httpRequestHandler);
}

@ApiClass(name: 'stumble', version: 'v1')
class Stumble {

  @ApiMethod(method: 'GET', path: '{user}')
  List<String> upon(String user, {String languages}) async {
  	Db db = new Db("mongodb://api:<EMAIL>:51523/gitr");
  	await db.open();
  	var collection = db.collection('repositories');

    var list = await collection
      .find(where
        .oneFrom('langs.lang',languages.split(',')))
      .toList();

  	await db.close();

    list = await rank(list, languages.split(','));
    return list;
  }

  List<String> rank(Map list, List<String> languages) async {<commit_msg>limit results to 1000<commit_after>import 'dart:io';

import 'package:logging/logging.dart';
import 'package:logging_handlers/server_logging_handlers.dart';
import 'package:rpc/rpc.dart';
import 'package:mongo_dart/mongo_dart.dart';

const String _API_PREFIX = '/api';
final ApiServer _apiServer =
    new ApiServer(apiPrefix: _API_PREFIX, prettyPrint: true);

main() async {
  // Add a simple log handler to log information to a server side file.
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen(new SyncFileLoggingHandler('hits.log'));
  if (stdout.hasTerminal) {
    Logger.root.onRecord.listen(new LogPrintHandler());
  }

  _apiServer.addApi(new Stumble());
  _apiServer.enableDiscoveryApi();

  HttpServer server = await HttpServer.bind(InternetAddress.ANY_IP_V4, 8080);
  server.listen(_apiServer.httpRequestHandler);
}

@ApiClass(name: 'stumble', version: 'v1')
class Stumble {

  @ApiMethod(method: 'GET', path: '{user}')
  List<String> upon(String user, {String languages}) async {
  	Db db = new Db("mongodb://api:<EMAIL>@<EMAIL>:51523/gitr");
  	await db.open();
  	var collection = db.collection('repositories');

    var list = await collection
      .find(where
        .oneFrom('langs.lang',languages.split(',')))
      .toList();

  	await db.close();

    list = await rank(list, languages.split(','));
    int end = list.length > 1000 ? 1000 : list.length;
    return list.getRange(0, end);
  }

  List<String> rank(Map list, List<String> languages) async {
{'fraction_non_alphanumeric': 0.14522821576763487, 'fraction_numerical': 0.012102351313969572, 'mean_word_length': 4.628404669260701, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6295248', 'n_tokens_mistral': 1000, 'n_tokens_neox': 962, 'n_words': 210}