<commit_before>import Vapor
import Fluent
import Foundation

// Model for a question
struct Question: Model {
    // Fields from database to fully represent question
    var id: Node? // Identifier to comform to model
    // Data to deal with Blob type
    let question: String
    let solution: Data
    let answer: String
    let subject: String
    let topic: String
    
    var exists: Bool = false

    // Initialize values
    init(question: String, solution: Data, answer: String, subject: String, topic: String) {
        self.question = question
        self.solution = solution
        self.answer = answer
        self.subject = subject
        self.topic = topic
    }
    
    // Getting data from database
    init(node: Node, in context: Context) throws {
        id = try node.extract("id")
        question = try node.extract("question")
        //question = try node.extract("question", transform: Question.stringToData)
        solution = try node.extract("solution", transform: Question.stringToData)
        answer = try node.extract("answer")
        subject = try node.extract("subject")
        topic = try node.extract("topic")
    }
    
    // Insert info into database
    // Probably unused
    func makeNode(context: Context) throws -> Node {
        return try Node(node: [
            "id": id,
            // Node data type can only use strings, ints, etc
            "question": question,
            //"question": question,
            "solution": Question.dataToString(solution),
            "answer": answer,
            "subject": subject,
            "topic": topic
        ])
    }
    
    // Needed to conform to model
    // Creates table if needed
    static func prepare(_ database: Database) throws {
        try database.create("questions") { questions in
            questions.id()
            questions.data("question")
            questions.data("solution")
            questions.string("answer")
            questions.string("subject")
            questions.string("topic")
        }
    }
    static func revert(_ database: Database) throws {
        try database.delete("questions")
    }
}

// Helper functions
extension Question {
    // Data to string is valid conversion
    // Data just sequence of bytes
    static func dataToString(_ data: Data) -> String {
        return String(data: data, encoding: .utf8)!
    }
    static func stringToData(_ dataString: String) -> Data {
        return dataString.data(using: .utf8)!
    }
}<commit_msg>Changed solution to base64<commit_after>import Vapor
import Fluent
import Foundation

// Model for a question
struct Question: Model {
    // Fields from database to fully represent question
    var id: Node? // Identifier to comform to model
    // Question and solution contain base64 png to deal with Blob type
    let question: String
    let solution: String
    let answer: String
    let subject: String
    let topic: String
    
    var exists: Bool = false

    // Initialize values
    init(question: String, solution: String, answer: String, subject: String, topic: String) {
        self.question = question
        self.solution = solution
        self.answer = answer
        self.subject = subject
        self.topic = topic
    }
    
    // Getting data from database
    init(node: Node, in context: Context) throws {
        id = try node.extract("id")
        question = try node.extract("question")
        //question = try node.extract("question", transform: Question.stringToData)
        //solution = try node.extract("solution", transform: Question.stringToData)
        solution = try node.extract("solution")
        answer = try node.extract("answer")
        subject = try node.extract("subject")
        topic = try node.extract("topic")
    }
    
    // Insert info into database
    // Probably unused
    func makeNode(context: Context) throws -> Node {
        return try Node(node: [
            "id": id,
            // Node data type can only use strings, ints, etc
            "question": question,
            //"question": question,
            "solution": solution,
            "answer": answer,
            "subject": subject,
            "topic": topic
        ])
    }
    
    // Needed to conform to model
    // Creates table if needed
    static func prepare(_ database: Database) throws {
        try database.create("questions") { questions in
            questions.id()
            questions.data("question")
            questions.data("solution")
            questions.string("answer")
            questions.string("subject")
            questions.string("topic")
        }
    }
    static func revert(_ database: Database) throws {
        try database.delete("questions")
    }
}

// Helper functions
/*extension Question {
    // Data to string is valid conversion
    // Data just sequence of bytes
    static func dataToString(_ data: Data) -> String {
        return String(data: data, encoding: .utf8)!
    }
    static func stringToData(_ dataString: String) -> Data {
        return dataString.data(using: .utf8)!
    }
}*/
{'fraction_non_alphanumeric': 0.09921414538310412, 'fraction_numerical': 0.0015717092337917485, 'mean_word_length': 2.15623062616243, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 9, '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': '6697941', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1260, 'n_words': 441}