<commit_before><?php
/**
 * @copyright (C) 2012 by iRail vzw/asbl
 * @license AGPLv3
 * @author <NAME> <jens at iRail.be>
 * @author <NAME> <hannes at iRail.be>
 */

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Import extends CI_Controller {
    
    function categories() {
        $json = $this->foursquare->api('venues/categories');
        
        $this->load->model('category_model');
        $this->category_model->truncate();
        
        foreach($json->response->categories as $category) {
            $this->process_category($category);
        }
    }
    
    private function process_category($category, $parent = '') {
        $data = array();
        $data['categoryid'] = $category->id;
        $data['name'] = $category->name;
        $data['icon'] = $category->icon;
        $data['parent'] = $parent;
        
        $this->category_model->insert($data);
        
        // recursive child categories
        if(isset($category->categories) && count($category->categories)) {
            foreach($category->categories as $subcategory) {
                $this->process_category($subcategory, $category->id);
            }
        }
    }

    function venuelist( $listid, $code = FALSE ){
        
        $this->config->load('foursquare', TRUE);
        $check = $this->config->item('cronjob_code', 'foursquare');
        
        if( $code != $check ){
            show_error('You don\'t have permission to access this page');
        }
        
        //get parameters
        $startdate = $this->input->get('from') ? $this->input->get('from') : time() ;
        $enddate = $this->input->get('till') ? $this->input->get('till') : time() ;
        $multiplier = $this->input->get('multi') ? $this->input->get('multi') : 2 ; //default = 2
        
        if ($json = $this->foursquare->api('lists/' . $listid )) {

            $list = array();
            $list['startdate'] = $startdate ;
            $list['enddate'] = $enddate ;
            $list['multiplier'] = $multiplier ;
            $list['listid'] = $listid ;
            $list['name'] = $json->response->list->name ;
            
            $this->load->model('venue_model');
            $this->venue_model->insert_list( $list );
            
            if( $list = $json->response->list->listItems->items ){
                $venuedata = array();
                foreach(  $list as $venue ){
                    $venue = $venue->venue ;
                    $category = reset( $venue->categories );
                    
                    $venuedata['listid'] = $listid ;
                    $venuedata['venueid'] = $venue->id ;
                    $venuedata['name'] = $venue->name ;
                    $venuedata['categoryid'] = $category->id ;
                    $venuedata['lon'] = $venue->location->lat ;
                    $venuedata['lat'] = $venue->location->lng ;
                    
                    $this->venue_model->insert( $venuedata );
                }
                
                echo count( $list ) . ' venues from list ' . $listid . ' imported.' ;
            }else{
                show_error('This list doesn\'t exist');
            }
            
        }
        echo $this->foursquare->error ;
    }
    
    function coordinates() {
        $url = 'http://data.appsforghent.be/poi/kotzones.json';
        $json = $this->_datatank($url);
        
        $this->load->model('region_model');
        $this->region_model->truncate();
        <commit_msg>Indentation<commit_after><?php
/**
 * @copyright (C) 2012 by iRail vzw/asbl
 * @license AGPLv3
 * @author <NAME> <jens at iRail.be>
 * @author <NAME> <hannes at iRail.be>
 */

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Import extends CI_Controller {
    
    function categories() {
        $json = $this->foursquare->api('venues/categories');
        
        $this->load->model('category_model');
        $this->category_model->truncate();
        
        foreach ($json->response->categories as $category) {
            $this->process_category($category);
        }
    }
    
    private function process_category($category, $parent = '') {
        $data = array();
        $data['categoryid'] = $category->id;
        $data['name'] = $category->name;
        $data['icon'] = $category->icon;
        $data['parent'] = $parent;
        
        $this->category_model->insert($data);
        
        // recursive child categories
        if (isset($category->categories) && count($category->categories)) {
            foreach ($category->categories as $subcategory) {
                $this->process_category($subcategory, $category->id);
            }
        }
    }
    
    function venuelist($listid, $code = FALSE) {
        
        $this->config->load('foursquare', TRUE);
        $check = $this->config->item('cronjob_code', 'foursquare');
        
        if ($code != $check) {
            show_error('You don\'t have permission to access this page');
        }
        
        //get parameters
        $startdate = $this->input->get('from') ? $this->input->get('from') : time();
        $enddate = $this->input->get('till') ? $this->input->get('till') : time();
        $multiplier = $this->input->get('multi') ? $this->input->get('multi') : 2; //default = 2
        

        if ($json = $this->foursquare->api('lists/' . $listid)) {
            
            $list = array();
            $list['startdate'] = $startdate;
            $list['enddate'] = $enddate;
            $list['multiplier'] = $multiplier;
            $list['listid'] = $listid;
            $list['name'] = $json->response->list->name;
            
            $this->load->model('venue_model');
            $this->venue_model->insert_list($list);
            
            if ($list = $json->response->list->listItems->items) {
                $venuedata = array();
                foreach ($list as $venue) {
                    $venue = $venue->venue;
                    $category = reset($venue->categories);
                    
                    $venuedata['listid'] = $listid;
                    $venuedata['venueid'] = $venue->id;
                    $venuedata['name'] = $venue->name;
                    $venuedata['categoryid'] = $category->id;
                    $venuedata['lon'] = $venue->location->lat;
                    $venuedata['lat'] = $venue->location->lng;
                    
                    $this->venue_model->insert($venuedata);
                }
                
                echo count($list) . ' venues from list ' . $listid . ' imported.';
            } else {
                show_error('This list doesn\'t exist');
            }
        
        }
        echo $this->foursquare->error;
    }
    
    function coordinates() {
        $url = 'http://data.appsforghent.be/poi/kotzones.json';
        $json = $this->_datatank($url);
        
        $this->load->model('region_model');
        $this->region_model->truncate();
        
{'fraction_non_alphanumeric': 0.16880524664955804, 'fraction_numerical': 0.001996007984031936, 'mean_word_length': 1.715834301200155, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 143, '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': '6418770', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1979, 'n_words': 342}