1

I cant figure out what the error is. I try to read out a CSV from my server and then to access the DateValues with an FUnction Called getZinsAnDatum.

The Chain begins in function:

$scope.calcZins = function database(ctrl, $scope) {....

I chained the results, reading out my CSV-Values via

getZinsAnDatum(dateee, fullDate)

works when I click twice or wait and click again. Guess it works, after clicking two times, because its load into the cache. The function itself returns a promise too, after i get Warning from this, pointing on the code lines from getZinsAnDatum(dateee, fullDate):

Warning: a promise was created in a handler at /localhost:8383/validations/js/index.js:269:17 but was not returned from it

Sorry if I miss fundamental concepts. I guess the Promises arent chained right or its to much traffic, because for every Value i detect (about 200) it downloads the hole CSV? therefore I wanted to inject the CSV once in my Alasql database and work from there.

But putting it in doesnt seem to work. Therefore could you help me out maybe? Down my code HTML and javascript:

I spared out some functions and variables, all variables are given and defined.

Javascript:

     /* global $scope, user,user.anpDat, user.zinsDiff, user.zinsJetz,user.zinsNext, user.nextAnpDat, user.AnzahlAnMonatenZwischenErsterAnpassungUndAktuellemDatum , user.Berechnung, ctrl.Berechnung, Promise, alasql*/

    angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache']).controller('AppCtrl', function ($scope) {

           this.fullDate = new Date("1999-12-20");
    this.fullDate2 = new Date("2000-01-20");
    this.fullDate3 = new Date("2010-03-19");


    this.date = fullDate.toISOString().substring(0, 10);
    this.date2 = fullDate2.toISOString().substring(0, 10);;
    this.date3 = fullDate3.toISOString().substring(0, 10);;

        var data = {};
        var url = 'tests/fib.csv';

        function getZinsAnDatum(dateee, fullDate) {
            return new Promise(function (resolve, reject) {
                alasql.promise('SELECT [1] FROM CSV("tests/fib.csv", {headers:false, })  WHERE [0] >=? AND [1]!="."', [dateee])
                        .then(function (data) {

                            var temp = data [1  ][1];

                            resolve(temp);

                        }).catch(function (err) {
                    console.log('Error:', err);

                });


            });
        }


        $scope.calcZins = function database(ctrl, $scope) {
            this.mybase = new alasql.Database('mybase');
            this.mybase.exec('CREATE TABLE one ');
            this.mybase.exec('SELECT [0][1] INTO one FROM CSV("tests/fib.csv", {headers:false, })');
            //this.mybase.exec('PRINT one'); //GIVES ERRORS, CANT READ UNDEFINED JSON Object

            calcZins2(ctrl, $scope);

            ;
        }


        function calcZins2(ctrl, $scope) {
            var user = new Object;
            var anpassen = false;
            user = angular.copy(ctrl);
            user.Berechnung;
            var Row;
            getZinsAnDatum(user.date2, user.fullDate2).then(function (resu) {


                // Code depending on result
                var value = parseFloat(resu.replace(",", "."));
               user.zinsJetz = value;
                Row.zinsJetz=user.zinsJetz;
                user.Berechnung.push(Row);

                nextAbschnitt(user, ctrl, $scope);
            }).catch(function () {
                // An error occurred
            });





            function nextAbschnitt(user, ctrl, $scope) {



                getZinsAnDatum(date3,fullDate3).then(function (resulte) {


                    // Code depending on result
                    var value = parseFloat(resulte.replace(",", "."));
                    user.zinsNext = value;
                    getZinsAnDatum(date, FullDate).then(function (result) {


                        // Code depending on result
                        var value3 = parseFloat(result.replace(",", "."));
                        user.zinsJetz = value3;

                        gO(user, ctrl, $scope);


                    }).catch(function () {
                        // An error occurred
                    });


                }).catch(function () {
                    // An error occurred
                });
            }
        }


    function getMonthsDifference(date1, date2) {
        var k = date1.getYear() * 12 + date1.getMonth();
        console.log(k + "k")
        var m2 = date2.getYear() * 12 + date2.getMonth();
        console.log(m2 + "m2")
        return (m2 - k + 1);
    }


        function gO(user, ctrl, $scope) {


var g = getMonthsDifference(user.date2 user.date3);
 user.AnzahlAnMonatenZwischenErsterAnpassungUndAktuellemDatum = g;

            var count = 0;


            var promiseFor = Promise.method(function (condition, action, value) {
                if (!condition(value))
                    return value;
                return action(value).then(promiseFor.bind(null, condition, action));
            });



 promiseFor(function (count) {
                return count < user.AnzahlAnMonatenZwischenErsterAnpassungUndAktuellemDatum;
            }, function (count) {
                //  ctrl.Berechnung = user.Berechnung;
                return getZinsAnDatum(date3, fullDate3 ).then(function (resulte) {

             // DO STUFF


                        ctrl.done = true; // Shows THE HTML div via ng-Show
                        ctrl.Berechnung = user.Berechnung;


                    return ++count;
                });


            }, 0).then(function (user) {

            });
        }


    });

HTML:

        <tr>    </tr>
        <tr>    </tr>
         <tr>    </tr>
          <tr>    </tr>
        <tr>    </tr>
       <tr><td>Zinssatz nach richtiger Anpassung:</td><td>     {{ctrl.zinssatzKorrekt}}</td></tr>
       <tr><td>Aktueller Zinssatz der Bank</td><td>{{ctrl.zinssatzAktuell}}</td></tr>
       <tr><td>Differenz: </td><td>{{ctrl.zinssatzAktuell-ctrl.zinssatzKorrekt}}</td></tr>
      <tr>    </tr>
      <tr>    </tr>
      <tr>    </tr>
        <tr>    </tr> 
          <tr>    </tr> 
            <tr>    </tr> 
              <tr>    </tr> 

       <tr>    </tr> <tr>    </tr>



          <tr>
<td>FIBOR/EURIBOR-Stichtag</td><td>maßgeblicher FIBOR/EURIBOR in %</td><td>FIBOR/EURIBOR-
Veränderung</td> <td>Veränderung
kumuliert</td> <td>Anpassung</td> <td>gebotene 
Anpassung</td>  <td>Zinssatz korrekt</td></tr>
       <tr  ng-class="Texttype" ng-repeat="row in ctrl.Berechnung track by $index">
           <td> {{row.anpDat}}</td><td>{{row.zinsJetz}} </td><td>{{row.zinsDiff}} </td> <td>{{row.veranderungKummuliert}} </td> <td>{{row.anpassen}} </td> <td>{{row.geboteneAnpassung}} </td>  <td>{{row.zinssatzKorrekt}} </td></tr>

       </table>
noob
  • 23
  • 7
  • PUSH PLEASE HELP :) – noob Feb 07 '17 at 16:43
  • 1
    That is a mountain of code. Please remove all code not relevant to the specific problem. See [mcve] – charlietfl Feb 07 '17 at 16:48
  • Deleted as much as I thought is still needed. All variables are given and defined. Guess its problem of my chain, starting at $scope.calcZins(). Also I wonder what I'm doing wrong, reading in teh CSV to my alasql table one. ..? Thank you very very much !!!! – noob Feb 07 '17 at 17:16

0 Answers0