BASIC User Group > Code Challenges

Database Code Challenge(s)

<< < (15/15)

John:
Sounds great!

I didn't use SB LIKE for the challenge EXTRACT. SB needs an easy to use JSON function.

http://www.json.org

Would rewriting the jsmn library in C BASIC count?  :)

Please kick off the new challenge thread when you have time.

AlyssonR:
Hi all,

I've taken a quick peek at the thread - and it looks like everyone's been having fun with it.

I've been on extended domestic maintenance (i.e. fixing stuff around the house AND fixing myself), and will likely only look in on occasion for a while more :( The trouble is that I have far too much on the go right now with harware, software AND hard/software projects simmering as well as trying to keep abreast of everything that needs fixing around the house.

John:
You sound busier than Santa's elves.  :)

AIR:
I wanted to give this a try using GO, here is what I have:


--- Code: Go ---package main import (        "fmt"        "io/ioutil"        "log"        "strings"         "gopkg.in/yaml.v2") func getRoot(obj interface{}) map[interface{}]interface{} {        return obj.(map[interface{}]interface{})}func getSection(obj interface{}, field string) map[interface{}]interface{} {        dict := obj.(map[interface{}]interface{})[field].(map[interface{}]interface{})        return dict} func dump(obj map[interface{}]interface{}, indent ...string) {        for key, val := range obj {                if key == "Address" {                        val = strings.ReplaceAll(val.(string), "\n", "\n\t\t   ")                }                if indent != nil {                        fmt.Println(indent[0], "\t", key, "=", val)                } else {                        fmt.Println("\t", key, "=", val)                }        }} func getArray(obj interface{}) []interface{} {        dict := obj.([]interface{})        return dict} func dumpArray(obj interface{}) {        for _, field := range obj.([]interface{}) {                switch t := field.(type) {                case string:                        fmt.Println("\t\t", t)                case map[interface{}]interface{}:                        set := []interface{}{t["var"], t["colour"], t["Matrix"]}                        // x := t["var"]                        for _, x := range set {                                if x != nil {                                        fmt.Println("\t\t", x)                                }                        }                }        }} func dumpList(obj interface{}) {        for _, x := range obj.([]interface{}) {                dump(x.(map[interface{}]interface{}))                println()        }} type Rec interface{} func main() {        var rec Rec        sep := strings.Repeat("-", 40)        data, err := ioutil.ReadFile("test.yml")        if err != nil {                log.Fatal(err)        }         err = yaml.Unmarshal(data, &rec)        if err != nil {                log.Fatal(err)        }         root := getRoot(rec)        recordTitle := root["RecordTitle"]        entryNumber := root["Entry No"]        recordType := root["RecordType"]        lastSavedTime := root["LastSavedTime"]        previousVersion := root["Previous Version"]        Species := getRoot(root["Species"])        Minerals := getRoot(Species)["Minerals"]         location := getSection(rec, "Location")        collectionData := getSection(rec, "Collection Data")        acquisitionData := getSection(rec, "Acquisition Data")        analyticalData := getSection(rec, "Analytical Data")        accessionData := getSection(rec, "Accession Data")        imageData := getSection(rec, "Image Data")         fmt.Println(sep)        fmt.Println("RecordTitle =", recordTitle)        fmt.Println("Entry No =", entryNumber)        fmt.Println(sep)         fmt.Println("Species\n\tMinerals")        dumpArray(Minerals)        fmt.Println(sep)         fmt.Println("Location")        dump(location)        fmt.Println(sep)         fmt.Println("Collection Data")        dump(collectionData)        fmt.Println(sep)         fmt.Println("Acquisition Data")        dump(acquisitionData)        fmt.Println(sep)         fmt.Println("Analytical Data")        fmt.Println("\tCommentary =", analyticalData["Commentary"])         zeunerite := getRoot(analyticalData["Zeunerite"])        fmt.Println("\n\tZeunerite")        dump(zeunerite, "\t")         zippeite := getRoot(analyticalData["Zippeite"])        fmt.Println("\n\tZippeite")        dump(zippeite, "\t")        fmt.Println(sep)         fmt.Println("Accension Data")        dump(accessionData)        fmt.Println(sep)         fmt.Println("Image Data")        fmt.Println("\tMugshot =", imageData["Mugshot"], "\n")        images := imageData["Images"]        dumpList(images)        fmt.Println(sep)         fmt.Println("DB Info")        fmt.Println("\tRecordType =", recordType)        fmt.Println("\tLastSavedTime =", lastSavedTime)        fmt.Println("\tPrevious Version =", previousVersion)        fmt.Println(sep)} 
And here is the output:

----------------------------------------
RecordTitle = Mineral Specimen Details
Entry No = ARC-99-000021
----------------------------------------
Species
   Minerals
       Zeunerite
       Rutherfordine
       Zippeite
       Chalcopyrite
       [Blister Copper Quartz Agate]
       [White Opal Transparent map[var:[Common Opal]]]
       Quartz
----------------------------------------
Location
    Address = South Terras Mine
         St Stephen in Brannel
         St Austell
         Cornwall, UK

    Grid Reference = SW 935 524
    GPS Coordinates = 50.33444,-4.90194
----------------------------------------
Collection Data
    collected by = Self collected
    Collection Date = 1979
----------------------------------------
Acquisition Data
    From = Self collected
    Field Ref No = F20180623-STUM-001
    Temp Ref No = TMP 0 0099
    Acquired Date = 14 Jul 1998
----------------------------------------
Analytical Data
   Commentary = 4 species

   Zeunerite
        .Report = AN-201808-14-01
        .Ref_Number = ZZ8088
        .comment = Colour and crystal form are typical for this location.
        .date = 14 Aug 2018

   Zippeite
        .comment = Colour is diagnostic for this location
        .date = 14 Aug 2018
        .Report = AN-201808-14-02
        .Ref_Number = ZZ9099
----------------------------------------
Accension Data
    Accession Date = 21 Sept 2000
    Sub-collection = Main
    Accession No = ZZ9099
----------------------------------------
Image Data
   Mugshot = img0001.jpg

    .filename = img0001.jpg
    .Title = Whole Specimen
    .TakenDate = 11 Nov 2018
    .Width = 11.5mm
    .camera = Fuji FinePix L55

    .filename = img0002.jpg
    .Title = Zeunerite & Chalcopyrite
    .TakenDate = 11 Nov 2018
    .FOV = 1.1mm
    .Camera = CL 1600 USB MicroCam

----------------------------------------
DB Info
   RecordType = 1
   LastSavedTime = 13/11/2018 13:18:37
   Previous Version = 13/11/2018 12:12:47
----------------------------------------


I've attached Linux and Windows binaries (scanned with VirusTotal, clean) cross-compiled on my Mac.

AIR.

John:
GO AIR!  :)

Navigation

[0] Message Index

[*] Previous page

Go to full version