a
    nfc                     @   s   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZmZmZmZ ed e
 Zeddd ZdS )zRoutes word clouds.    N)BottlerouteviewresponserequestabortZSVGz*/surveys/<name>/reading/<number>/cloud.pngc                 C   s  t | \}}tjdr@ttjd}t |t | |}t 	| }|t
| d dkrtj \}}d|_tdd tdD }|t|t
| d d	 d
dd ||t
| d  D }	tjddddddddd|ddd|	}
|j|
dd | d | d |jd d |jd d |jd d |jd d t }|j|ddd d! d"t_ |! S t"d#S d S )$Nselected_answerstypecloud)d   r   c                 s   s   | ]}|  V  qd S N)strip).0line r   /var/www/vevn/routes/cloud.py	<genexpr>       z!generate_cloud.<locals>.<genexpr>zstatic/stopwords.txtwords, c                 s   s   | ]
}|V  qd S r   r   )r   commentr   r   r   r      r   questionz0/usr/share/fonts/cantarell/Cantarell-Regular.otfi        whiteTSet1      )Z	font_pathwidthheightZmin_font_sizerandom_stateZbackground_colorZcollocationsZcollocation_thresholdcolormap	stopwordsZ	max_wordsZmin_word_lengthbilinear)interpolationFtoprightbottomleftsvgi  tight)formatdpibbox_incheszimage/svg+xmli  )#surveyparser
get_surveyr   querygetjsonloadsfilter_surveyget_metadataget_readingsint
matplotlibpyplotsubplotsfigsizesetopenupdatesplitjoin	wordcloudZ	WordCloudgenerateimshow	get_xaxisset_visible	get_yaxisspinesioBytesIOsavefigr   content_typegetvaluer   )namenumbersurvey_r   readingsfigaxr#   textZ
word_cloudoutputr   r   r   generate_cloud
   sN    
 $rW   )__doc__r3   textwraprI   r/   readingparserpandasr9   rB   bottler   r   r   r   r   r   user
   rW   r   r   r   r   <module>   s   0 
