def main():

    print("Reading and analyzing file...")
    spectrum, freqs = ReadAndAnalyze(inPath)

    print(len(freqs))
    print(len(spectrum[0]))

    print("Scaling logarithmically (kinda)...")
    for i, s in enumerate(spectrum):
        spectrum[i] = list(map(loggish, s))

    print("Generating linear scale...")
    scale = scales.linear(domain=[spectrum.min(),
                                  spectrum.max()],
                          codomain=[1, 10])

    print("Normalizing spectrum data...")
    datapoints = list(map(lambda x: list(map(scale, x)), spectrum))

    print("Trimming spectrum data post-normalization...")
    for i, x in enumerate(datapoints):
        for j, v in enumerate(x):
            if v > 9:
                datapoints[i][j] = 9

    print("Generating bars...")
    bars = BarsND(datapoints, bar_width=1, bar_depth=1)

    print("Rendering...")
    code = bars.render(backend=OpenScadBackend)

    print("Saving to file...")
    with open(outPath, "w") as f:
        f.write(code)
Ejemplo n.º 2
0
def main():

  print "Reading and analyzing file..."
  spectrum, freqs = ReadAndAnalyze(inPath)

  print len(freqs)
  print len(spectrum[0])


  print "Scaling logarithmically (kinda)..."
  for i, s in enumerate(spectrum):
    spectrum[i] = map(loggish, s)

  print "Generating linear scale..."
  scale = scales.linear(domain=[spectrum.min(), spectrum.max()],
                        codomain=[1, 10])

  print "Normalizing spectrum data..."
  datapoints = map(lambda x: map(scale, x), spectrum)

  print "Trimming spectrum data post-normalization..."
  for i, x in enumerate(datapoints):
    for j, v in enumerate(x):
        if v > 9:
          datapoints[i][j] = 9

  print "Generating bars..."
  bars = BarsND(datapoints,
                bar_width=1,
                bar_depth=1)

  print "Rendering..."
  code = bars.render(backend=OpenScadBackend)

  print "Saving to file..."
  with open(outPath, "w") as f:
      f.write(code)
Ejemplo n.º 3
0
import csv
from itertools import chain

from tangible import scales
from tangible.shapes.bars import BarsND
from tangible.backends.openscad import OpenScadBackend


# Read data into list
datapoints = [list() for i in xrange(9)]
with open('analytics-full-13.csv', 'r') as datafile:
    reader = csv.DictReader(datafile)
    for row in reader:
        date = row['Day']
        month = int(date.split('/', 1)[0])
        visits = int(row['Visits'])
        datapoints[month - 1].append(visits)


# Normalize data
all_datapoints = list(chain.from_iterable(datapoints))
scale = scales.linear([min(all_datapoints), max(all_datapoints)], [10, 150])
datapoints = map(lambda x: map(scale, x), datapoints)


# Create shape
bars = BarsND(datapoints, bar_width=7, bar_depth=7, center_layers=False)

code = bars.render(backend=OpenScadBackend)
print(code)