<commit_before>package main

import (
	"encoding/csv"
	"flag"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
	"time"

	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

var (
	host   *string
	dbname *string
	col    *string
	out    *string
	fields *string
	keys   = StringArray{}
)

func init() {
	host = flag.String("H", "localhost:27017", "The host and port of the mongod instance you wish to connect to")
	dbname = flag.String("db", "testDB", "The output file that will be written to")
	//user = flag.String("user", "", "The user you wish to authenticate with")
	//pass = flag.String("pass", "", "The pass you wish to authenticate with")
	col = flag.String("c", "testCol", "The collection you wish to output")
	flag.Var(&keys, "f", "fields to output")
	// query := flag.String("query", "collection.csv", "The output file that will be written to")
	out = flag.String("o", "collection.csv", "The output file that will be written to")
}

var flattened = make(map[string]interface{})

func flatten(input bson.M, lkey string, flattened *map[string]interface{}) {
	for rkey, value := range input {
		key := lkey + rkey
		if _, ok := value.(string); ok {
			(*flattened)[key] = value.(string)
		} else if _, ok := value.(float64); ok {
			(*flattened)[key] = value.(float64)
		} else if _, ok := value.(int); ok {
			(*flattened)[key] = value.(int)
		} else if _, ok := value.(int64); ok {
			(*flattened)[key] = value.(int64)
		} else if _, ok := value.(bool); ok {
			(*flattened)[key] = value.(bool)
		} else if _, ok := value.(time.Time); ok {
			(*flattened)[key] = value.(time.Time).Format("2006-01-02T15:04:05Z07:00")
		} else if _, ok := value.(bson.ObjectId); ok {
			(*flattened)[key] = value.(bson.ObjectId).Hex()
		} else if _, ok := value.([]interface{}); ok {
			for i := 0; i < len(value.([]interface{})); i++ {
				if _, ok := value.([]string); ok {
					stringI := string(i)
					(*flattened)[stringI] = value.(string)
				} else if _, ok := value.([]int); ok {
					stringI := string(i)
					(*flattened)[stringI] = value.(int)
				} else {
					flatten(value.([]interface{})[i].(bson.M), key+"."+strconv.Itoa(i)+".", flattened)
				}
			}<commit_msg>[BUG] Cast without type assertion<commit_after>package main

import (
	"encoding/csv"
	"flag"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
	"time"

	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

var (
	host   *string
	dbname *string
	col    *string
	out    *string
	fields *string
	keys   = StringArray{}
)

func init() {
	host = flag.String("H", "localhost:27017", "The host and port of the mongod instance you wish to connect to")
	dbname = flag.String("db", "testDB", "The output file that will be written to")
	//user = flag.String("user", "", "The user you wish to authenticate with")
	//pass = flag.String("pass", "", "The pass you wish to authenticate with")
	col = flag.String("c", "testCol", "The collection you wish to output")
	flag.Var(&keys, "f", "fields to output")
	// query := flag.String("query", "collection.csv", "The output file that will be written to")
	out = flag.String("o", "collection.csv", "The output file that will be written to")
}

var flattened = make(map[string]interface{})

func flatten(input bson.M, lkey string, flattened *map[string]interface{}) {
	for rkey, value := range input {
		key := lkey + rkey
		if _, ok := value.(string); ok {
			(*flattened)[key] = value.(string)
		} else if _, ok := value.(float64); ok {
			(*flattened)[key] = value.(float64)
		} else if _, ok := value.(int); ok {
			(*flattened)[key] = value.(int)
		} else if _, ok := value.(int64); ok {
			(*flattened)[key] = value.(int64)
		} else if _, ok := value.(bool); ok {
			(*flattened)[key] = value.(bool)
		} else if _, ok := value.(time.Time); ok {
			(*flattened)[key] = value.(time.Time).Format("2006-01-02T15:04:05Z07:00")
		} else if _, ok := value.(bson.ObjectId); ok {
			(*flattened)[key] = value.(bson.ObjectId).Hex()
		} else if _, ok := value.([]interface{}); ok {
			for i := 0; i < len(value.([]interface{})); i++ {
				if _, ok := value.([]string); ok {
					stringI := string(i)
					(*flattened)[stringI] = value.(string)
				} else if _, ok := value.([]int); ok {
					stringI := string(i)
					(*flattened)[stringI] = value.(int)
				} else {
					if _, ok := value.([]interface{})[i].(bson.M); ok {
						flatten(value.([]interface{})[i].(bson.M), key+"."+strconv.Itoa(i)+".", flattened)
					}
				}
			}
{'fraction_non_alphanumeric': 0.19990882151812173, 'fraction_numerical': 0.015500341919307043, 'mean_word_length': 3.5283797729618165, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6823303', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1589, 'n_words': 422}