<commit_before>var express = require('express');
var db = require('../libs/db');
var _ = require('underscore');
var router = module.exports = express.Router();

function transformRepositoryToV1(r) {
  return {
    owner: r.owner.login,
    name: r.name,
    url: r.url,
    avatarUrl: r.owner.avatar_url,
    description: r.description,
    stars: r.stargazers_count,
    forks: r.forks_count
  };
}

router.get('/', function(req, res) {
    res.json({
        'languages_url': req.domain + '/languages',
        'trending_url': req.domain + '/trending',
        'showcases_url': req.domain + '/showcases'
    });
});

router.get('/languages', function(req, res, next) {
    db.Trending.find({}, 'language', function(err, data) {
        if (err) return next(err);
        if (!data) return next(new Error('Unable to retrieve data from database!'));
        var languages = _.map(data, function(d) { return d.language });
        languages = _.reject(languages, function(l) { return l.slug === 'all' });
        languages = _.sortBy(languages, function(l) { return l.name });
        res.json(languages);
    });
});

// Get rid of this soon...
router.get('/trending', function(req, res, next) {
    var language = req.query.language || 'all';
    var since = req.query.since || 'daily';
    db.Trending.findOne({ 'language.slug': language }, 'repositories.' + since, function(err, data) {
        if (err) return next(err);<commit_msg>Fix for null owners<commit_after>var express = require('express');
var db = require('../libs/db');
var _ = require('underscore');
var router = module.exports = express.Router();

function transformRepositoryToV1(r) {
  return {
    owner: (r.owner || {}).login,
    name: r.name,
    url: r.url,
    avatarUrl: (r.owner || {}).avatar_url,
    description: r.description,
    stars: r.stargazers_count,
    forks: r.forks_count
  };
}

router.get('/', function(req, res) {
    res.json({
        'languages_url': req.domain + '/languages',
        'trending_url': req.domain + '/trending',
        'showcases_url': req.domain + '/showcases'
    });
});

router.get('/languages', function(req, res, next) {
    db.Trending.find({}, 'language', function(err, data) {
        if (err) return next(err);
        if (!data) return next(new Error('Unable to retrieve data from database!'));
        var languages = _.map(data, function(d) { return d.language });
        languages = _.reject(languages, function(l) { return l.slug === 'all' });
        languages = _.sortBy(languages, function(l) { return l.name });
        res.json(languages);
    });
});

// Get rid of this soon...
router.get('/trending', function(req, res, next) {
    var language = req.query.language || 'all';
    var since = req.query.since || 'daily';
    db.Trending.findOne({ 'language.slug': language }, 'repositories.' + since, function(err, data) {
        if (err) return next(err);
{'fraction_non_alphanumeric': 0.1769177608845888, 'fraction_numerical': 0.000691085003455425, 'mean_word_length': 3.183526011560694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2173120', 'n_tokens_mistral': 946, 'n_tokens_neox': 941, 'n_words': 224}