Browse Source

small fixes for dataeditor and StockWeekly, added pandas to dependencies

master
phryk 4 weeks ago
parent
commit
3e9ce4bdca
3 changed files with 24 additions and 26 deletions
  1. 7
    7
      example.py
  2. 15
    18
      poobrains/svg/plot.py
  3. 2
    1
      setup.py

+ 7
- 7
example.py View File

@@ -161,7 +161,6 @@ class NASAApproaches(poobrains.svg.plot.Dataset):
161 161
         #rawdata = [rawdata]
162 162
 
163 163
         #self.data = pandas.DataFrame(data=rawdata, index=[spkid])
164
-        app.debugger.set_trace()
165 164
         #self.data = pandas.DataFrame([pandas.Series(rawdata, index=rawindex)])
166 165
         self.data = pandas.DataFrame(pandas.Series(rawdata))
167 166
 
@@ -191,21 +190,23 @@ class StockWeekly(poobrains.svg.plot.Dataset):
191 190
             date = datetime.datetime(y, m, d)
192 191
 
193 192
             x = date.timestamp()
194
-            y = float(datapoint['1. open']) + float(datapoint['4. close']) / 2
195
-            error_lower = y - float(datapoint['3. low'])
196
-            error_upper = y - float(datapoint['2. high'])
193
+            #x = date
194
+            #y = (float(datapoint['1. open']) + float(datapoint['4. close'])) / 2
195
+            y = float(datapoint['4. close'])
196
+            #error_lower = y - float(datapoint['3. low'])
197
+            #error_upper = y - float(datapoint['2. high'])
197 198
 
198 199
             #self.add_datapoint(x, y, error_lower=error_lower, error_upper=error_upper)
199 200
             rawdata[x] = y
200 201
 
201
-        self.data = pandas.DataFrame(data=rawdata)
202
+        self.data = pandas.DataFrame(pandas.Series(data=rawdata))
202 203
 
203 204
 
204 205
 
205 206
 class ConstrainedRandom(poobrains.svg.plot.Dataset):
206 207
 
207 208
     def fill(self, magnitude: int = 2, length: int = 16) -> None:
208
-        #app.debugger.set_trace()
209
+
209 210
         magnitude, length = int(magnitude), int(length)
210 211
 
211 212
         ranges = []
@@ -240,7 +241,6 @@ class Sine(poobrains.svg.plot.Dataset):
240 241
 
241 242
     def fill(self, length=10):
242 243
 
243
-        import pudb; pudb.set_trace()
244 244
         inc = (2 * math.pi) / (length - 1)
245 245
         #inc = 1.0 / (length - 1)
246 246
 

+ 15
- 18
poobrains/svg/plot.py View File

@@ -95,7 +95,7 @@ class Dataset(poobrains.auth.Protected):
95 95
 
96 96
 
97 97
     @name.setter
98
-    def set_name(self, value):
98
+    def name(self, value):
99 99
         self._name = value
100 100
 
101 101
 
@@ -634,7 +634,9 @@ class EditorNewSessionFieldset(poobrains.form.Fieldset):
634 634
             'plot_kind': 'scatter',
635 635
             'action': None,
636 636
             'action_data': None,
637
-            'data': None
637
+            'title': None,
638
+            'description': None,
639
+            'data': None,
638 640
         }
639 641
 
640 642
         return redirect(DataEditor.url(handle=handle, mode='full'))
@@ -708,8 +710,10 @@ class EditorLoadFieldset(poobrains.form.Fieldset):
708 710
                         dataset = StoredDataset.load(dataset_name)
709 711
                         dataset.permissions['read'].check(g.user)
710 712
                         instance.dataset = dataset
711
-                        session['editor-sessions'][instance.handle_string]['data'] = instance.dataset.data.to_dict()
712 713
                         session['editor-sessions'][instance.handle_string]['action'] = None
714
+                        session['editor-sessions'][instance.handle_string]['title'] = instance.dataset.title
715
+                        session['editor-sessions'][instance.handle_string]['description'] = instance.dataset.description
716
+                        session['editor-sessions'][instance.handle_string]['data'] = instance.dataset.data.to_dict()
713 717
                     except StoredDataset.DoesNotExist:
714 718
                         flash('Unknown stored dataset: %s' % dataset_name, 'error')
715 719
 
@@ -738,8 +742,10 @@ class EditorLoadFieldset(poobrains.form.Fieldset):
738 742
 
739 743
                     dataset.permissions['read'].check(g.user)
740 744
                     instance.dataset = dataset
741
-                    session['editor-sessions'][instance.handle_string]['data'] = instance.dataset.data.to_dict()
742 745
                     session['editor-sessions'][instance.handle_string]['action'] = None
746
+                    session['editor-sessions'][instance.handle_string]['title'] = instance.dataset.title
747
+                    session['editor-sessions'][instance.handle_string]['description'] = instance.dataset.description
748
+                    session['editor-sessions'][instance.handle_string]['data'] = instance.dataset.data.to_dict()
743 749
                     del(self.fields['dynamic'])
744 750
                     self.fields['dataset'].readonly = False
745 751
 
@@ -787,7 +793,10 @@ class DataEditor(poobrains.auth.ProtectedForm):
787 793
             editor_session = session['editor-sessions'][self.handle_string]
788 794
 
789 795
             self.dataset = Dataset()
796
+            self.dataset.name = self.handle_string
790 797
             self.dataset.plot_kind = editor_session['plot_kind'] or 'scatter'
798
+            self.dataset.title = editor_session['title']
799
+            self.dataset.description = editor_session['description']
791 800
             self.dataset.data = pandas.DataFrame.from_dict(editor_session['data'])
792 801
 
793 802
             if len(self.dataset.data):
@@ -805,20 +814,6 @@ class DataEditor(poobrains.auth.ProtectedForm):
805 814
             self.save_dataset = poobrains.form.Button(type='submit', label='Save dataset')
806 815
 
807 816
 
808
-    #@poobrains.helpers.themed
809
-    #def view(self, mode='full', **kwargs):
810
-
811
-        #if not self.handle_string:
812
-        #    return redirect(type(self)(handle=new_editor_handle()).url('full'))
813
-
814
-        #if self.handle_string and self.handle_string in session:
815
-        #    #self.dataset = session[self.handle_string]
816
-        #    self.dataset = Dataset()
817
-        #    self.dataset.data = pandas.DataFrame.from_dict(session['editor-sessions'][self.handle_string])
818
-
819
-        #return poobrains.helpers.ThemedPassthrough(super(DataEditor, self).view(mode=mode, **kwargs))
820
-
821
-
822 817
     def process(self, submit):
823 818
 
824 819
         if submit.startswith('new.'):
@@ -826,6 +821,8 @@ class DataEditor(poobrains.auth.ProtectedForm):
826 821
 
827 822
         elif submit.startswith('load.'):
828 823
             self.fields['load'].process(submit, self)
824
+            if len(self.dataset.data):
825
+                self.plot_kind = PlotKindFieldset(self.handle_string)
829 826
             #session[self.handle_string] = self.data
830 827
 
831 828
         elif submit.startswith('plot_kind.'):

+ 2
- 1
setup.py View File

@@ -16,7 +16,8 @@ setup(
16 16
         'pillow', # for image manipulation and generation (primarily to generate captchas)
17 17
         'markdown',
18 18
         'pyproj', # map projection
19
-        'pretty-bad-protocol' # formerly 'gnupg'
19
+        'pretty-bad-protocol', # formerly 'gnupg'
20
+        'pandas'
20 21
     ],
21 22
 
22 23
     extras_require={

Loading…
Cancel
Save