Skip to content

Commit

Permalink
removed gif code
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon committed Feb 17, 2021
1 parent 92e19aa commit b106468
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 142 deletions.
33 changes: 0 additions & 33 deletions som_opendata/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,39 +180,6 @@ def toPopulationRelative(data, geolevel, values=ns(), perValue=10000):
continue
region["values"][index] = region["values"][index]*float(perValue) / populationDict[code]

@lru_cache(maxsize=100)
def pngFromSvg(svg):
with Image(blob=svg, format='svg', width=500, height=400).convert('png') as img:
return img.make_blob()

def createGif(frameQuantity, data, template, legend, geolevel, title, colors, scale, subtitle='', locations=[], isRelative=False):
svgFrames = []
for frame in range(frameQuantity):
dataDict = dataToTemplateDict(
data=data,
colors=colors,
title=title,
subtitle=subtitle,
locations=locations,
geolevel=geolevel,
isRelative=isRelative,
frame=frame,
scale=scale
)
svg = template.format(**dict(dataDict, legend=legend)).encode('utf8')
svgFrames.append(svg)
with Image() as gif:
for svg in svgFrames:
pngFrame = pngFromSvg(svg)
with Image(blob=pngFrame, format='png') as frame:
gif.sequence.append(frame)
with gif.sequence[-1] as frame:
frame.delay = 50 # centiseconds
gif.type = 'optimize'
gif.format = 'gif'
return gif.make_blob()


def getNiceDivisor(population):
from .scale import niceFloorValue
currentMin = None
Expand Down
109 changes: 0 additions & 109 deletions som_opendata/map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
getNiceDivisor,
toPopulationRelative,
fillLegend,
createGif,
pngFromSvg,
frameCssAnimation,
createAnimatedSvg,
)
Expand Down Expand Up @@ -1063,47 +1061,6 @@ def test_renderMap_members_givenTemplate(self):
)
self.assertB2BEqual(result)

def test_createGif_manyFrames(self):
data = ns.loads("""\
dates: [2019-01-01, 2018-01-01]
values: [143, 500]
countries:
ES:
name: España
values: [143, 500]
ccaas:
'01':
name: Andalucía
values: [123, 500]
'09':
name: Catalunya
values: [20, 0]
""")
template = Path('data/maps/mapTemplates/mapTemplate_dummy.svg').read_text(encoding='utf8')
gradient = Gradient('#e0ecbb', '#384413')
scale = LogScale(higher=500).nice()
img = createGif(
frameQuantity=2, data=data, template=template, legend='', colors=gradient, scale=scale,
geolevel='ccaa',title='One')
self.assertNsEqual(getBlobInfo(img), """\
format: GIF
isAnimation: true
numFrames: 2
""")

def test_createGif_oneFrame(self):
template = Path('data/maps/mapTemplates/mapTemplate_dummy.svg').read_text(encoding='utf8')
gradient = Gradient('#e0ecbb', '#384413')
scale = LogScale(higher=143).nice()
img = createGif(
frameQuantity=1, data=manyRegions, template=template, legend='', colors=gradient, scale=scale,
geolevel='ccaa',title='One')
self.assertNsEqual(getBlobInfo(img), """\
format: GIF
isAnimation: false
numFrames: 1
""")

def test_renderMap_membersRangeDates(self):
template = mapTemplateSource.getTemplate(geolevel='ccaa', lang='en')
locations = relativeData.getCodesByGeolevel('ccaa')
Expand All @@ -1123,72 +1080,6 @@ def test_getNiceDivisor_(self):

self.assertEqual(result, 50000)

def test_createGif_cachedFrames(self):
pngFromSvg.cache_clear()
data = ns.loads("""\
dates: [2019-01-01, 2018-01-01]
values: [143, 500]
countries:
ES:
name: España
values: [143, 500]
ccaas:
'01':
name: Andalucía
values: [123, 500]
'09':
name: Catalunya
values: [20, 0]
""")
template = Path('data/maps/mapTemplates/mapTemplate_dummy.svg').read_text(encoding='utf8')
gradient = Gradient('#e0ecbb', '#384413')
scale = LogScale(higher=500).nice()
createGif(
frameQuantity=2, data=data, template=template, legend='', colors=gradient, scale=scale,
geolevel='ccaa',title='One')
createGif(
frameQuantity=2, data=data, template=template, legend='', colors=gradient, scale=scale,
geolevel='ccaa',title='One')
cache_info = pngFromSvg.cache_info()
self.assertEqual(
[cache_info.hits, cache_info.misses],
[2,2]
)

def test_createGif_notCachedFrames(self):
pngFromSvg.cache_clear()
data = ns.loads("""\
dates: [2019-01-01, 2018-01-01]
values: [143, 500]
countries:
ES:
name: España
values: [143, 500]
ccaas:
'01':
name: Andalucía
values: [123, 500]
'09':
name: Catalunya
values: [20, 0]
""")
template = Path('data/maps/mapTemplates/mapTemplate_dummy.svg').read_text(encoding='utf8')
gradient = Gradient('#e0ecbb', '#384413')
scale = LogScale(higher=500).nice()
createGif(
frameQuantity=2, data=data, template=template, legend='', colors=gradient, scale=scale,
geolevel='ccaa',title='One')

createGif(
frameQuantity=2, data=data, template=template, legend='', colors=gradient, scale=scale,
geolevel='ccaa',title='Different')

cache_info = pngFromSvg.cache_info()
self.assertEqual(
[cache_info.hits, cache_info.misses],
[0,4]
)

def test_renderMap_members_cachedAfterChangedValues(self):
locations = relativeData.getCodesByGeolevel('ccaa')
template = mapTemplateSource.getTemplate(geolevel='ccaa', lang='en')
Expand Down

0 comments on commit b106468

Please sign in to comment.