Saturday, 31 August 2019

Modify a value during a CAAnimation BOUNTY

Say you have a simple animation

    let e : CABasicAnimation = CABasicAnimation(keyPath: "strokeEnd")
    e.duration = 2.0
    e.fromValue = 0 
    e.toValue = 1.0
    e.repeatCount = .greatestFiniteMagnitude
    self.someLayer.add(e, forKey: nil)

of a layer

private lazy var someLayer: CAShapeLayer

It's quite easy to read the value of strokeEnd each animation step.

Just change to a custom layer

private lazy var someLayer: CrazyLayer

and then

class CrazyLayer: CAShapeLayer {
    override func draw(in ctx: CGContext) {
        print("Yo \(presentation()!.strokeEnd)")
        super.draw(in: ctx)
    }
}

It would be very convenient to actually be able to set the property values of the layer at each step.

Example,

class CrazyLayer: CAShapeLayer {
    override func draw(in ctx: CGContext) {
        print("Yo \(presentation()!.strokeEnd)")
        strokeStart = presentation()!.strokeEnd - 0.3
        super.draw(in: ctx)
    }
}

Of course you can't do that -

attempting to modify read-only layer

Perhaps you could have a custom animatable property

class LoopyLayer: CAShapeLayer {
    @NSManaged var trick: CGFloat

    override class func needsDisplay(forKey key: String) -> Bool {
        if key == "trick" { return true }
        return super.needsDisplay(forKey: key)
    }

    ... somehow for each frame
    strokeEnd = trick * something
    backgroundColor = alpha: trick
}

How can I "manually" set the values of the animatable properties, each frame?

Is there perhaps a way to simply supply (override?) a function which calculates the value each frame?? How to set values each frame, of some of the properties, from a calculation of other properties or perhaps another custom property?



from Modify a value during a CAAnimation BOUNTY

CallKit call blocking extension automatically disables occasionally

I have an app with a CallKit call blocking extension. Generally it works fine, but on some devices it occasionally becomes disabled by itself (well, in fact by iOS I guess) after a while – so user has to go to Settings and re-enable it again manually. However, there is no any visible reason for such behavior: the volume of blocked phone numbers data is small enough (the app works even with larger datasets most of the time, so it shouldn't be a memory issue), numbers are sorted in a right order (ascending), there are no duplicated numbers etc. It is also quite hard to reproduce the problem. It feels like something from "outer world" interferes with the extension (another app with extension?), but there are no proofs.

What may be the reason of such auto-disabling and how to avoid that?

Any help would be appreciated.

Thanks!



from CallKit call blocking extension automatically disables occasionally

pyserial with multiprocessing gives me a ctype error

Hi I'm trying to write a module that lets me read and send data via pyserial. I have to be able to read the data in parallel to my main script. With the help of a stackoverflow user, I have a basic and working skeleton of the program, but when I tried adding a class I created that uses pyserial (handles finding port, speed, etc) found here I get the following error:

File "", line 1, in runfile('C:.../pythonInterface1/Main.py', wdir='C:/Users/Daniel.000/Desktop/Daniel/Python/pythonInterface1')

File "C:...\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile execfile(filename, namespace)

File "C:...\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/Daniel.000/Desktop/Daniel/Python/pythonInterface1/Main.py", line 39, in p.start()

File "C:...\Anaconda3\lib\multiprocessing\process.py", line 112, in start self._popen = self._Popen(self)

File "C:...\Anaconda3\lib\multiprocessing\context.py", line 223, in _Popen return _default_context.get_context().Process._Popen(process_obj)

File "C:...\Anaconda3\lib\multiprocessing\context.py", line 322, in _Popen return Popen(process_obj)

File "C:...\Anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 89, in init reduction.dump(process_obj, to_child)

File "C:...\Anaconda3\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj)

ValueError: ctypes objects containing pointers cannot be pickled

This is the code I am using to call the class in SerialConnection.py

import multiprocessing 
from time import sleep
from operator import methodcaller

from SerialConnection import SerialConnection as SC

class Spawn:
    def __init__(self, _number, _max):
        self._number = _number
        self._max = _max
        # Don't call update here

    def request(self, x):
        print("{} was requested.".format(x))

    def update(self):
        while True:
            print("Spawned {} of {}".format(self._number, self._max))
            sleep(2)

if __name__ == '__main__':
    '''
    spawn = Spawn(1, 1)  # Create the object as normal
    p = multiprocessing.Process(target=methodcaller("update"), args=(spawn,)) # Run the loop in the process
    p.start()
    while True:
        sleep(1.5)
        spawn.request(2)  # Now you can reference the "spawn"
    '''
    device = SC()
    print(device.Port)
    print(device.Baud)
    print(device.ID)
    print(device.Error)
    print(device.EMsg)
    p = multiprocessing.Process(target=methodcaller("ReadData"), args=(device,)) # Run the loop in the process
    p.start()
    while True:
        sleep(1.5)
        device.SendData('0003')

What am I doing wrong for this class to be giving me problems? Is there some form of restriction to use pyserial and multiprocessing together? I know it can be done but I don't understand how...

here is the traceback i get from python

Traceback (most recent call last): File "C:...\Python\pythonInterface1\Main.py", line 45, in p.start()

File "C:...\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\process.py", line 105, in start self._popen = self._Popen(self)

File "C:...\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\context.py", line 223, in _Popen return _default_context.get_context().Process._Popen(process_obj)

File "C:...\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\context.py", line 322, in _Popen return Popen(process_obj)

File "C:...\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\popen_spawn_win32.py", line 65, in init reduction.dump(process_obj, to_child)

File "C:...\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj) ValueError: ctypes objects containing pointers cannot be pickled



from pyserial with multiprocessing gives me a ctype error

Go to Typescript Source Definition instead of Compiled Definition in Visual Studio Code

I am working on a typescript project with Visual Studio Code including multiple npm packages structured like this:

  • Source code: /src/index.ts
  • Compiled code: /dist/...

When I right click on imported objects and choose "Go to Definition" or click F12 or by clicking on the object with holding down CTRL, Visual Studio Code opens the corresponding .d.ts file in /dist

vscode go to definition vscode open .d.ts

However, I want VSCode to open the corresponding .ts file in /src

.ts file

Is it possible to change this behavior, as it is really annoying to manually search for the source file.

I've created git repo, so that you can try it yourself: https://github.com/flolude/stackoverflow-typescript-go-to-definition

  • you just need to run yarn bootstrap in order to replicate the issue.


from Go to Typescript Source Definition instead of Compiled Definition in Visual Studio Code

interactive scatter highlight in bokeh

I am trying to visualise sensor output in relation to its path.
I plot path as scatter in one figure and some range of signal amplitude in the second figure. I need to visualise (highlight) a path point at which the particular reading was taken.

I started using bokeh as a backend and in general, got very good results with visualisations I need. But I am stuck on this particular interaction.

I would like to have some marker like a vertical line anchored in the middle of the figure. When I move/scroll the amplitude plot (the bottom one), I would like to highlight the point on the path plot where the reading closest to the marker line was taken.

The example code:
(I would like to anchor the marker line and add interaction between the red dot and the vertical line taking an index of the signal, which is not implemented.)

import numpy as np
import pandas as pd
from bokeh.io import output_file
from bokeh.models import ColumnDataSource, HoverTool, Span
from bokeh.plotting import figure, show
from bokeh.layouts import gridplot

output_file('interactive_path_sig.html', title="interactive path")

class InteractivePath():
    def __init__(self):
        x = np.arange(0, 1000, 0.5)
        self.df = pd.DataFrame({"x": x,
                                "y": np.sin(x),
                                "z": np.cos(x)})
        self.source = ColumnDataSource(self.df)

    def plot_path(self):
        plt = figure(tools=self.TOOLS, title = "Sensor Path")
        plt.scatter(x="x", y="y",source=self.source, 
                    line_color=None, size = 6)
        # TODO implement interaction instead of hard coded index
        index=500    # this is where I think I need to create working callback
        print("x={}, y={}".format(self.df['x'][index], self.df['y'][index]))
        plt.circle(x=self.df['x'][index], y=self.df['y'][index], 
                   fill_color="red", size=15)
        hover = HoverTool()
        hover.tooltips=[("index", "@index"), ("senosr","@z")]
        plt.add_tools(hover)
        return plt

    def plot_signal(self):
        plt = figure(tools=self.TOOLS, x_range=(450, 550), title="Signal Amplitude")
        plt.line(x="index", y="z", source=self.source, line_color="black", line_width=2)
        # TODO implement interaction instead of hard coded index
        index = 500  # I think this needs emit some singal to other plot
        vline = Span(location=index, dimension='height', line_color='red', line_width=3)
        plt.renderers.extend([vline])
        return plt

    def get_grid(self):
        """ place visualisation in a grid and display"""
        grid = gridplot([[self.plot_path()], [self.plot_signal()]], 
                 sizing_mode='stretch_both',)
        return grid

    def vis_main(self):
        """ use all visualisations"""
        show(self.get_grid())

if __name__=="__main__":
    vis = InteractivePath()
    vis.vis_main()

enter image description here enter image description here



from interactive scatter highlight in bokeh

How to disable drag to select in RecyclerView SelectionTracker?

I need to disable the drag to select feature of RecyclerView selection tracker. Currently after long press item gets selected and if I continue dragging continuous items are selected. I need to ensure that rest items are not selected.

Tried working something with the inbuild implementations but nothing worked.



from How to disable drag to select in RecyclerView SelectionTracker?

jQuery parallax effect and lagging

I have a page with a header and a content. When scrolling down, the header menu sticks to the top while the content has a kind of "parallax" effect (it moves up faster than the header does, which is what I need).

My small jQuery script works well for the "parallax" effect but when the scroll down is at its max, the content starts to stutter/lag. The script seems to keep on trying to move the content up continuously (at least with an Apple Magic Mouse), which creates this ungraceful side effect.

How can I prevent that ?

PS: I exaggerated the parallax effect in the JSFiddle in order to clearly show the stuttering issue.

PPS: make sure you have a scrollable page when testing (small browser height), otherwise, the effect and issue won't happen, of course.

//sticky header menu

$(window).scroll(function() {
  if ($(document).scrollTop() > 92) {
    if (!$('.fixed').length) {
      $('.menu').addClass('fixed');
    }
  } else {
    if ($('.fixed').length) {
      $('.menu').removeClass('fixed');
    }
  }
});

// Parallax of content on scroll

var iCurScrollPos = 0;
$(window).scroll(function() {
    iCurScrollPos = $(this).scrollTop();
    $('.content').css('margin-top', -iCurScrollPos * 1.2 + 'px')
});
body {
  width: 100%;
  height: 100%;
  margin: 0px;
  padding: 0px;
  background: #ccc;
}

header {
  position: relative;
  width: 100%;
  background: #fff;
  z-index: 1;
  height: 146px;
}

.void {
  position: relative;
  width: 100%;
  height: 100px;
}

.menu {
  position: relative;
  width: 100%;
  height: 54px;
  background: #aaa;
}

.fixed {
  position: fixed;
  left: 0px;
  top: 0px;
}

img {
  width: 100%
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 

<header>
  <div class="void"></div>
  <nav class="menu"></nav>
</header> 

<div class="content">
  <img src="https://farm8.staticflickr.com/7632/16990947835_3894284fd8_b.jpg">
</div>

JSFiddle

https://jsfiddle.net/v6g43mkL/1/



from jQuery parallax effect and lagging

How can I use the Google OAuth2 ID token with node.js / passport.js to verify if the user is valid and authenticated?

On my front end, I'm using vue.js (not that that matters) and with the Google OAuth flow, I get back an id_token from:

let googleAuthIdToken = await this.auth2.currentUser
            .get()
            .getAuthResponse().id_token;

I want to then pass that token to my node.js server (Express / Passport) to verify that the user is allowed to login.

I want to use passport and send back a JWT to the front end in my response.

Can someone please guide me as to how to accomplish this?



from How can I use the Google OAuth2 ID token with node.js / passport.js to verify if the user is valid and authenticated?

Error 1016 when executing Argo Tunnel from Node child_process

Cloudflare Argo Tunnel from Node child_process

I have an electron app from which I would like to spawn a child process that executes

cloudflared tunnel --url localhost:3000

inside a certain directory. Executing this from cmd inside that directory instantiates the argo tunnel as expected, and the url works while the process is running. This is how I am executing the command from the electron app:

const { spawn } = require('child_process')

let tunnel = spawn('cloudflared', ['tunnel', '--url', 'localhost:4000'], {
  stdio: 'inherit', // Will use process .stdout, .stdin, .stderr
  cwd: 'c://cloudflare'
})

I can see the normal console output from cloudflare indicating that the tunnel has been established and my server is responding at some-random-name.trycloudflare.com. However, when the process is started from within the electron app, I get Error 1016 displayed on a cloudflare error page.

Does anyone have experience with Argo Tunnel and child_process?



from Error 1016 when executing Argo Tunnel from Node child_process

Intermitent EAI_AGAIN error on node server

My nodejs application connects to an external url and uses the response. The application works fine most of the time, but I am getting EAI_AGAIN occasionally.

error:{code:EAI_AGAIN, errno:EAI_AGAIN,syscall:getaddrinfo,hostname:**.com,host:***.com,port:443}

I went through somequestions related EAI_AGAIN. Did not solve my purpose. Saw that this error occurs when DNS name resolving fails.

My concerns are 1) When I checked the logs. There were many successful requests just before the failed request and also there were many successful requests just after the failed request. Why it failed for only one request?

2) What could be the actual cause? I would like to know all the possibilities.

3) Can the reason be any issue on the external service to which we are connecting?

Note: We are using docker containers. If this has anything to do.



from Intermitent EAI_AGAIN error on node server

Load STL from buffer (not path) in Three.js

I want to display a user-uploaded STL file using Three.js.

My file is sent to the front-end via a GET request: res.sendFile(path). The problem is, I can't use that raw data to load a file without editing Three.js's loader!

Could someone help me edit the STLLoader to accept the result of res.sendFile(path) instead of a path (URL)?

After a week of head-scratching, I've had no luck!

Here's the code of STLLoader.js:

import {
  BufferAttribute,
  BufferGeometry,
  DefaultLoadingManager,
  FileLoader,
  Float32BufferAttribute,
  LoaderUtils,
  Vector3
} from "three/build/three.module.js";


var STLLoader = function ( manager ) {

    this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;

};

STLLoader.prototype = {

    constructor: STLLoader,

    load: function ( url, onLoad, onProgress, onError ) {

        var scope = this;

        var loader = new FileLoader( scope.manager );
        loader.setPath( scope.path );
        loader.setResponseType( 'arraybuffer' );
        loader.load( url, function ( text ) {

            try {

                onLoad( scope.parse( text ) );

            } catch ( exception ) {

                if ( onError ) {

                    onError( exception );

                }

            }

        }, onProgress, onError );

    },

    setPath: function ( value ) {

        this.path = value;
        return this;

    },

    parse: function ( data ) {

        function isBinary( data ) {

            var expect, face_size, n_faces, reader;
            reader = new DataView( data );
            face_size = ( 32 / 8 * 3 ) + ( ( 32 / 8 * 3 ) * 3 ) + ( 16 / 8 );
            n_faces = reader.getUint32( 80, true );
            expect = 80 + ( 32 / 8 ) + ( n_faces * face_size );

            if ( expect === reader.byteLength ) {

                return true;

            }

            // An ASCII STL data must begin with 'solid ' as the first six bytes.
            // However, ASCII STLs lacking the SPACE after the 'd' are known to be
            // plentiful.  So, check the first 5 bytes for 'solid'.

            // Several encodings, such as UTF-8, precede the text with up to 5 bytes:
            // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
            // Search for "solid" to start anywhere after those prefixes.

            // US-ASCII ordinal values for 's', 'o', 'l', 'i', 'd'

            var solid = [ 115, 111, 108, 105, 100 ];

            for ( var off = 0; off < 5; off ++ ) {

                // If "solid" text is matched to the current offset, declare it to be an ASCII STL.

                if ( matchDataViewAt( solid, reader, off ) ) return false;

            }

            // Couldn't find "solid" text at the beginning; it is binary STL.

            return true;

        }

        function matchDataViewAt( query, reader, offset ) {

            // Check if each byte in query matches the corresponding byte from the current offset

            for ( var i = 0, il = query.length; i < il; i ++ ) {

                if ( query[ i ] !== reader.getUint8( offset + i, false ) ) return false;

            }

            return true;

        }

        function parseBinary( data ) {

            var reader = new DataView( data );
            var faces = reader.getUint32( 80, true );

            var r, g, b, hasColors = false, colors;
            var defaultR, defaultG, defaultB, alpha;

            // process STL header
            // check for default color in header ("COLOR=rgba" sequence).

            for ( var index = 0; index < 80 - 10; index ++ ) {

                if ( ( reader.getUint32( index, false ) == 0x434F4C4F /*COLO*/ ) &&
                    ( reader.getUint8( index + 4 ) == 0x52 /*'R'*/ ) &&
                    ( reader.getUint8( index + 5 ) == 0x3D /*'='*/ ) ) {

                    hasColors = true;
                    colors = new Float32Array( faces * 3 * 3 );

                    defaultR = reader.getUint8( index + 6 ) / 255;
                    defaultG = reader.getUint8( index + 7 ) / 255;
                    defaultB = reader.getUint8( index + 8 ) / 255;
                    alpha = reader.getUint8( index + 9 ) / 255;

                }

            }

            var dataOffset = 84;
            var faceLength = 12 * 4 + 2;

            var geometry = new BufferGeometry();

            var vertices = new Float32Array( faces * 3 * 3 );
            var normals = new Float32Array( faces * 3 * 3 );

            for ( var face = 0; face < faces; face ++ ) {

                var start = dataOffset + face * faceLength;
                var normalX = reader.getFloat32( start, true );
                var normalY = reader.getFloat32( start + 4, true );
                var normalZ = reader.getFloat32( start + 8, true );

                if ( hasColors ) {

                    var packedColor = reader.getUint16( start + 48, true );

                    if ( ( packedColor & 0x8000 ) === 0 ) {

                        // facet has its own unique color

                        r = ( packedColor & 0x1F ) / 31;
                        g = ( ( packedColor >> 5 ) & 0x1F ) / 31;
                        b = ( ( packedColor >> 10 ) & 0x1F ) / 31;

                    } else {

                        r = defaultR;
                        g = defaultG;
                        b = defaultB;

                    }

                }

                for ( var i = 1; i <= 3; i ++ ) {

                    var vertexstart = start + i * 12;
                    var componentIdx = ( face * 3 * 3 ) + ( ( i - 1 ) * 3 );

                    vertices[ componentIdx ] = reader.getFloat32( vertexstart, true );
                    vertices[ componentIdx + 1 ] = reader.getFloat32( vertexstart + 4, true );
                    vertices[ componentIdx + 2 ] = reader.getFloat32( vertexstart + 8, true );

                    normals[ componentIdx ] = normalX;
                    normals[ componentIdx + 1 ] = normalY;
                    normals[ componentIdx + 2 ] = normalZ;

                    if ( hasColors ) {

                        colors[ componentIdx ] = r;
                        colors[ componentIdx + 1 ] = g;
                        colors[ componentIdx + 2 ] = b;

                    }

                }

            }

            geometry.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
            geometry.addAttribute( 'normal', new BufferAttribute( normals, 3 ) );

            if ( hasColors ) {

                geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
                geometry.hasColors = true;
                geometry.alpha = alpha;

            }

            return geometry;

        }

        function parseASCII( data ) {

            var geometry = new BufferGeometry();
            var patternSolid = /solid([\s\S]*?)endsolid/g;
            var patternFace = /facet([\s\S]*?)endfacet/g;
            var faceCounter = 0;

            var patternFloat = /[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source;
            var patternVertex = new RegExp( 'vertex' + patternFloat + patternFloat + patternFloat, 'g' );
            var patternNormal = new RegExp( 'normal' + patternFloat + patternFloat + patternFloat, 'g' );

            var vertices = [];
            var normals = [];

            var normal = new Vector3();

            var result;

            var groupVertexes = [];
            var groupCount = 0;
            var startVertex = 0;
            var endVertex = 0;

            while ( ( result = patternSolid.exec( data ) ) !== null ) {

                startVertex = endVertex;

                var solid = result[ 0 ];

                while ( ( result = patternFace.exec( solid ) ) !== null ) {

                    var vertexCountPerFace = 0;
                    var normalCountPerFace = 0;

                    var text = result[ 0 ];

                    while ( ( result = patternNormal.exec( text ) ) !== null ) {

                        normal.x = parseFloat( result[ 1 ] );
                        normal.y = parseFloat( result[ 2 ] );
                        normal.z = parseFloat( result[ 3 ] );
                        normalCountPerFace ++;

                    }

                    while ( ( result = patternVertex.exec( text ) ) !== null ) {

                        vertices.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
                        normals.push( normal.x, normal.y, normal.z );
                        vertexCountPerFace ++;
                        endVertex ++;

                    }

                    // every face have to own ONE valid normal

                    if ( normalCountPerFace !== 1 ) {

                        console.error( 'THREE.STLLoader: Something isn\'t right with the normal of face number ' + faceCounter );

                    }

                    // each face have to own THREE valid vertices

                    if ( vertexCountPerFace !== 3 ) {

                        console.error( 'THREE.STLLoader: Something isn\'t right with the vertices of face number ' + faceCounter );

                    }

                    faceCounter ++;

                }

                groupVertexes.push( { startVertex: startVertex, endVertex: endVertex } );
                groupCount ++;

            }

            geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
            geometry.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );

            if ( groupCount > 0 ) {

                for ( var i = 0; i < groupVertexes.length; i ++ ) {

                    geometry.addGroup( groupVertexes[ i ].startVertex, groupVertexes[ i ].endVertex, i );

                }

            }

            return geometry;

        }

        function ensureString( buffer ) {

            if ( typeof buffer !== 'string' ) {

                return LoaderUtils.decodeText( new Uint8Array( buffer ) );

            }

            return buffer;

        }

        function ensureBinary( buffer ) {

            if ( typeof buffer === 'string' ) {

                var array_buffer = new Uint8Array( buffer.length );
                for ( var i = 0; i < buffer.length; i ++ ) {

                    array_buffer[ i ] = buffer.charCodeAt( i ) & 0xff; // implicitly assumes little-endian

                }

                return array_buffer.buffer || array_buffer;

            } else {

                return buffer;

            }

        }

        // start

        var binData = ensureBinary( data );

        return isBinary( binData ) ? parseBinary( binData ) : parseASCII( ensureString( data ) );

    }

};

export { STLLoader };

Some extra info:

The file data, when received by my frontend, looks like this: �u#;�O_?����W�Bt��B���A��B凪B�F�A���BJJ�BȧA�ۢ>#(q>�k?��B

I've been attempting to encode it as an ArrayBuffer using:

  var enc = new TextEncoder();
  var arrayBuffer = enc.encode(fileString).buffer;



from Load STL from buffer (not path) in Three.js

How to save and load selected variables in tensorflow 2.0 using tf.train.Checkpoint?

How do I save selected variables in tensorflow 2.0 shown below in a file and load them into some defined variables in another code?

class manyVariables:
    def __init__(self):
        self.initList = [None]*100
        for i in range(100):
            self.initList[i] = tf.Variable(tf.random.normal([5,5]))
        self.makeSomeMoreVariables()

    def makeSomeMoreVariables(self):
        self.moreList = [None]*10
        for i in range(10):
            self.moreList[i] = tf.Variable(tf.random.normal([3,3]))

    def saveVariables(self):
        # how to save self.initList's 3,55 and 60th elements and self.moreList's 4th element

What is the most tf2 specific way to save variables and restore them?



from How to save and load selected variables in tensorflow 2.0 using tf.train.Checkpoint?

User authentication in Laravel from xenforo database with using several tables

I have 2 databases: one from Laravel and other from XenForo 2. On Laravel, registration should not take place, but only on the forum in order to reduce data duplication and eliminate the out of sync if it happens for some reason.

There are 2 tables in XF: xf_users - stores basic user information, and xf_user_authenticate - stores a serialized array string with a password hash.

It is necessary to authenticate through these 2 tables. User entered username/password correctly - logged into Laravel CMS.

Connecting to a third-party database is simple: manually register the connection in the User model as follows:

protected $ connection = 'forum';
protected $ table = 'xf_users';
public $ timestamps = false;

I also created the Password model for obtaining passwords from the xf_user_authenticate table with a method for obtaining a password hash:

class Password extends Model
{
     protected $ fillable = ['data'];
     protected $ connection = 'forum';
     protected $ table = 'xf_user_authenticate';
     public $ timestamps = false;

     public static function getPassHash ($ uid) {
         $ data = Password :: firstWhere ('user_id', '=', $ uid) -> get ();
         return unserialize ($ data-> data) ['hash'];
     }
}

Further, as I understand it, I need to make a custom guard and provider, and here I can no longer understand what to do next...

How can I use these 2 tables for authentication in the laravel engine?



from User authentication in Laravel from xenforo database with using several tables

Calendar iframe doesn't show all latest created events(especially shared calendar events)

I've managed to embed Google Calendar into a React component, but the problem is I could observe that the embedded calendar doesn't get the latest events that is added to the email that is authenticated with gapi.

The calendar iframe URL is this https://calendar.google.com/calendar/b/1/embed?src={VALID_CALENDAR_EMAIL}

calendar.util.js

const CALENDAR_EMBED_BASE_URL =
  'https://calendar.google.com/calendar/embed?src=';

export const getCalendarEmbedUrl = email =>
  `${CALENDAR_EMBED_BASE_URL}${email}`;


CalendarIframe.jsx component

import React, { PureComponent } from 'react';
import { getCalendarEmbedUrl } from 'calendar.util.js';

class CalendarIframe extends PureComponent {
  render() {
    const { email } = this.props;
    const embedUrl = getCalendarEmbedUrl(email);

    return (
      <div className="calendarEmbedWrapper">
        <iframe
          title="Calendar"
          id="calendarEmbed"
          width="100%"
          src={embedUrl}
        />
      </div>
    );
  }
}


What's a way to ensure the embedded calendar is as dynamic as it should be?



from Calendar iframe doesn't show all latest created events(especially shared calendar events)

transaction for prepared statements using Node mssql

I want to create an Express REST API and will use MSSQL for the database part. I use the mssql module and created a database class first

import sql, { ConnectionPool, PreparedStatement, IProcedureResult } from 'mssql';
import { injectable } from 'inversify';

import { IDatabase } from './IDatabase';
import { InternalServerErrorException } from '../../interfaceAdapters/httpExceptions/InternalServerErrorException';
import * as databaseConfig from '../../config/DatabaseConfig';

@injectable()
export class Database implements IDatabase {
    public connectionPool: ConnectionPool;

    constructor() {
        this.connectionPool = new sql.ConnectionPool(databaseConfig);
    }

    public connect = async (): Promise<void> => {
        try {
            await this.connectionPool.connect();
        } catch (error) {
            throw error;
        }
    }

    public query = async (builder: Function) : Promise<IProcedureResult<any>> => {
        try {
            const rawStatement: PreparedStatement = new sql.PreparedStatement(this.connectionPool);

            const queryInfo: any = builder(rawStatement);
            const { preparedStatement, queryString, queryParams = {} }: { preparedStatement: PreparedStatement, queryString: string, queryParams: object } = queryInfo;

            await preparedStatement.prepare(queryString);
            const queryResult: IProcedureResult<any> = await preparedStatement.execute(queryParams);
            await preparedStatement.unprepare();

            return queryResult;
        } catch (error) {
            throw new InternalServerErrorException(error.message);
        }
    }
}

As you can see I created a query function with a builder parameter. I have multiple queries from multiple classes and don't want to write the same code over and over again so I pass in only the things that differ from query to query. A basic example would be my fetchUserById example

public fetchUserById = async (params: any[]): Promise<QueryResult> => {
    try {
        const queryResult: IProcedureResult<any> = await this.database.query((preparedStatement: PreparedStatement) => {
            preparedStatement.input('userId', sql.Numeric);

            const queryString: string = `
                SELECT *
                FROM users
                WHERE id = @userId
            `;

            const queryParams: object = {
                userId: params[0]
            };

            return {
                preparedStatement, 
                queryString,
                queryParams,
            };
        });

        return new QueryResult(queryResult.recordset, queryResult.rowsAffected.length);
    } catch (error) {
        throw error;
    }
}

The database provides the preparedStatement object and the query passes back the updated statement, the query string and the parameters.

This code works fine but doesn't provide the possibility for transactional queries.

I found some information about prepared statements here and about transactions here but don't know how to execute transactional queries using prepared statements.

Would someone mind explaining how to use the mssql module to provide the possibility using prepared statements within transactions? My database query function should provide a functionality giving access to write something like this in my query file

  • begin transaction
  • run insertQuery one
  • run insertQuery two
  • end transaction


from transaction for prepared statements using Node mssql

ConstraintLayout with growing TextViews claiming equal space if needed

Is it possible to in ConstrainLayout have two textviews constrained such that they take 50% of the space each if they need it, and if they don't the other grows to fill the space.

A Correct: When texts are short the textViews do not interfere with eachother. equal

B Correct: The short left textView yields space to the longer right one leftsmall

C Correct: Share horizontal space equally and grow vertically

correct

D Incorrect: Right textView grows on expense of the left textView.

rightlonger

E Incorrect: Right textView grows vertically rather than filling available horizontal space.

enter image description here

I've tried a lot of things. It think layout_width="wrap_content" or layout_constraintWidth_default="wrap" is a must since it is the textViews' only way to communicate how much space it wants.

Experimented with:

layout_constrainedWidth="true/false"
layout_constraintWidth_default="spread/wrap"
layout_constraintWidth_max="wrap"
layout_constraintHorizontal_weight="1" // with 0dp as width

Experimentation mostly with the textViews in a horizontal chain, since there is a symmetry in the problem I think a symmetric solution makes sense.

Has anyone managed this or is it just impossible? I do not know why it behaves as it does with the second element in the chain being 'heavier' than the first one forcing it to be the only one to grow vertically.



from ConstraintLayout with growing TextViews claiming equal space if needed

how to access sub? urls keeping the main url connection alive

trying to access some sub? php urls/endpoints to get overall h/w health status. Problem here is I could able to access only from browser those urls/endpoints with long cookies. when i try with python and linux cmd line getting 401 error

url_login_page=https://10.10.10.10/designs/imm/index.php

below are the available php's I wanted to access with python & curl, and able view the content of these php's from browser without issues

{"home.php":"1"},{"event-log.php":"4"},{"event-notification.php":"5"},
{"event-notification.php":"5"},{"service-problems.php":"6"},{"servicesettings.php":"7"},{"download-service-data.php":"8"},{"serverfirmware.php":"9"},{"remote-control.php":"10"},
{"server-properties.php":"11"},{"server-actions.php":"12"},{"fanlist.php":"13"},
{"power-modules.php":"14"},{"disk-list.php":"15"},{"memorylist.php":"16"},
{"cpu-list.php":"17"},{"server-timeouts.php":"18"},{"immproperties.php":"19"},
{"user-list.php":"20"},{"network-properties.php":"21"},{"immsecurity.php":"22"},
{"backup-restore.php":"23"},{"pxe-network-boot.php":"28"},{"osfailurescreen.php":"29"},{"feature-on-demand.php":"80"}]

Not able to get the cookie value with requests

$ r=requests.get(url,auth=(usr,pswd),verify=False)
$r 
<Response [200]>
$ r.cookies
 <RequestsCookieJar[]>

And I tried with headers too but no luck

h = httplib2.Http(".cache",disable_ssl_certificate_validation=True,timeout=3)
            h.add_credentials(user_login,Password)
            headers={'Cookie': 'sessionKey=%s' % session_id }
            resp,content = h.request(
            url,
            'GET',headers=headers   
            )

Please help me how could i access the sub urls? is it possible to access with existing XHR headerss ?



from how to access sub? urls keeping the main url connection alive

Can't get voiceStateUpdate when user disconnect from server

I have a function of automatized channels,

All changes are triggered with voiceStateUpdate event.

All work very good but when a user disconnect from server, voiceStateUpdate is not called...

So how can i know if user leave with disconnection from server ?



from Can't get voiceStateUpdate when user disconnect from server

RequestAnimationFrame speeds up/slows down periodically

From my understanding, requestAnimationFrame should run as close as possible to the browser's frame rate, which is approximately 60fps. To ensure that this is indeed taking place, I have been logging timestamps for each requestAnimationFrame invocation like so:

function animate(now){
    console.log(now);
    window.requestAnimationFrame(animate);
}
window.requestAnimationFrame(animate);

Console.log data shows that invocations are consistently taking place approximately 0.016674 milliseconds apart, thus indicating that the frame rate is ≈ 60fps (59.9736116108912fps to be exact).

Console.logs (sample data):

Timestamp   FPS               (Current - previous) timestamp
------------------------------------------------------------
100.226     59.97361161       0.016674
116.9       59.97361161       0.016674
133.574     59.97361161       0.016674
   .             .               .
   .             .               .
150.248     59.97361161       0.016674
166.922     59.97361161       0.016674
183.596     59.97361161       0.016674
200.27      59.97361161       0.016674

Up to this point, requestAnimationFrame invocations are occurring at consistent time intervals, and no invocation lags behind/executes too fast.

However, modifying the contents of the animate() function to execute a relatively more complex function, results in requestAnimationFrame invocations which are not as consistent.

Console.logs (sample data):

Timestamp       FPS               (Current - previous) timestamp
------------------------------------------------------------
7042.73         59.97361161       0.016674
7066.278        42.4664515        0.023548
7082.952        59.97361161       0.016674
7099.626        59.97361161       0.016674
   .                 .                .
   .                 .                .
17104.026       59.97361161       0.016674
17112.84        113.4558657       0.008814
17129.514       59.97361161       0.016674
17146.188       59.97361161       0.016674

As can be seen in the above data sample, timestamp differences and frame rates are no longer steady, and sometimes occur too soon/too late, resulting in inconsistent frame rates. Had requestAnimationFrame been consistently invoked late, I would have assumed that due to JavaScript's single-threaded nature, complex code residing in the animate() function is taking too long to execute, and thus results in a delayed requestAnimationFrame invocation. However, since requestAnimationFrame is occasionally being invoked too early, this does not seem to be the case.

My code (skeleton):

for (var counter = 0; counter < elements.length; counter ++) //10 elements
{
  //some other code

  animate(element);
}

function animate(element)
{
   // function invocation => performs some complex calculations and animates the element passed in as a parameter

   window.requestAnimationFrame(function() { animate(element) } );
}

As can be seen in the above code snippet, requestAnimationFrame is being invoked multiple times for each element, within the initial for loop. RequestAnimationFrame invocations are also intended to go on infinitely, for each of the elements. Since the animation to be performed is highly time-critical (animation timing is very important in this scenario and should be as accurate as possible), it is essential that requestAnimationFrame invocations occur at consistent time intervals throughout. These time intervals should ideally be as close as possible to 0.016674 (≈ 60fps).

  1. Would you be able to clarify what is causing this inconsistent requestAnimationFrame behaviour?

  2. Can any optimisations be applied to ensure that requestAnimationFrame invocations are executed at consistent time intervals?

  3. Can better timing accuracy be achieved if I use some other kind of functionality (say, web workers in combination with the setInterval() function)?



from RequestAnimationFrame speeds up/slows down periodically

Friday, 30 August 2019

Load STL from buffer (not path) in Three.js

I want to display a user-uploaded STL file using Three.js.

My file is sent to the front-end via a GET request: res.sendFile(path). The problem is, I can't use that raw data to load a file without editing Three.js's loader!

Could someone help me edit the STLLoader to accept the result of res.sendFile(path) instead of a path (URL)?

After a week of head-scratching, I've had no luck!

Here's the code of STLLoader.js:

import {
  BufferAttribute,
  BufferGeometry,
  DefaultLoadingManager,
  FileLoader,
  Float32BufferAttribute,
  LoaderUtils,
  Vector3
} from "three/build/three.module.js";


var STLLoader = function ( manager ) {

    this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;

};

STLLoader.prototype = {

    constructor: STLLoader,

    load: function ( url, onLoad, onProgress, onError ) {

        var scope = this;

        var loader = new FileLoader( scope.manager );
        loader.setPath( scope.path );
        loader.setResponseType( 'arraybuffer' );
        loader.load( url, function ( text ) {

            try {

                onLoad( scope.parse( text ) );

            } catch ( exception ) {

                if ( onError ) {

                    onError( exception );

                }

            }

        }, onProgress, onError );

    },

    setPath: function ( value ) {

        this.path = value;
        return this;

    },

    parse: function ( data ) {

        function isBinary( data ) {

            var expect, face_size, n_faces, reader;
            reader = new DataView( data );
            face_size = ( 32 / 8 * 3 ) + ( ( 32 / 8 * 3 ) * 3 ) + ( 16 / 8 );
            n_faces = reader.getUint32( 80, true );
            expect = 80 + ( 32 / 8 ) + ( n_faces * face_size );

            if ( expect === reader.byteLength ) {

                return true;

            }

            // An ASCII STL data must begin with 'solid ' as the first six bytes.
            // However, ASCII STLs lacking the SPACE after the 'd' are known to be
            // plentiful.  So, check the first 5 bytes for 'solid'.

            // Several encodings, such as UTF-8, precede the text with up to 5 bytes:
            // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
            // Search for "solid" to start anywhere after those prefixes.

            // US-ASCII ordinal values for 's', 'o', 'l', 'i', 'd'

            var solid = [ 115, 111, 108, 105, 100 ];

            for ( var off = 0; off < 5; off ++ ) {

                // If "solid" text is matched to the current offset, declare it to be an ASCII STL.

                if ( matchDataViewAt( solid, reader, off ) ) return false;

            }

            // Couldn't find "solid" text at the beginning; it is binary STL.

            return true;

        }

        function matchDataViewAt( query, reader, offset ) {

            // Check if each byte in query matches the corresponding byte from the current offset

            for ( var i = 0, il = query.length; i < il; i ++ ) {

                if ( query[ i ] !== reader.getUint8( offset + i, false ) ) return false;

            }

            return true;

        }

        function parseBinary( data ) {

            var reader = new DataView( data );
            var faces = reader.getUint32( 80, true );

            var r, g, b, hasColors = false, colors;
            var defaultR, defaultG, defaultB, alpha;

            // process STL header
            // check for default color in header ("COLOR=rgba" sequence).

            for ( var index = 0; index < 80 - 10; index ++ ) {

                if ( ( reader.getUint32( index, false ) == 0x434F4C4F /*COLO*/ ) &&
                    ( reader.getUint8( index + 4 ) == 0x52 /*'R'*/ ) &&
                    ( reader.getUint8( index + 5 ) == 0x3D /*'='*/ ) ) {

                    hasColors = true;
                    colors = new Float32Array( faces * 3 * 3 );

                    defaultR = reader.getUint8( index + 6 ) / 255;
                    defaultG = reader.getUint8( index + 7 ) / 255;
                    defaultB = reader.getUint8( index + 8 ) / 255;
                    alpha = reader.getUint8( index + 9 ) / 255;

                }

            }

            var dataOffset = 84;
            var faceLength = 12 * 4 + 2;

            var geometry = new BufferGeometry();

            var vertices = new Float32Array( faces * 3 * 3 );
            var normals = new Float32Array( faces * 3 * 3 );

            for ( var face = 0; face < faces; face ++ ) {

                var start = dataOffset + face * faceLength;
                var normalX = reader.getFloat32( start, true );
                var normalY = reader.getFloat32( start + 4, true );
                var normalZ = reader.getFloat32( start + 8, true );

                if ( hasColors ) {

                    var packedColor = reader.getUint16( start + 48, true );

                    if ( ( packedColor & 0x8000 ) === 0 ) {

                        // facet has its own unique color

                        r = ( packedColor & 0x1F ) / 31;
                        g = ( ( packedColor >> 5 ) & 0x1F ) / 31;
                        b = ( ( packedColor >> 10 ) & 0x1F ) / 31;

                    } else {

                        r = defaultR;
                        g = defaultG;
                        b = defaultB;

                    }

                }

                for ( var i = 1; i <= 3; i ++ ) {

                    var vertexstart = start + i * 12;
                    var componentIdx = ( face * 3 * 3 ) + ( ( i - 1 ) * 3 );

                    vertices[ componentIdx ] = reader.getFloat32( vertexstart, true );
                    vertices[ componentIdx + 1 ] = reader.getFloat32( vertexstart + 4, true );
                    vertices[ componentIdx + 2 ] = reader.getFloat32( vertexstart + 8, true );

                    normals[ componentIdx ] = normalX;
                    normals[ componentIdx + 1 ] = normalY;
                    normals[ componentIdx + 2 ] = normalZ;

                    if ( hasColors ) {

                        colors[ componentIdx ] = r;
                        colors[ componentIdx + 1 ] = g;
                        colors[ componentIdx + 2 ] = b;

                    }

                }

            }

            geometry.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
            geometry.addAttribute( 'normal', new BufferAttribute( normals, 3 ) );

            if ( hasColors ) {

                geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
                geometry.hasColors = true;
                geometry.alpha = alpha;

            }

            return geometry;

        }

        function parseASCII( data ) {

            var geometry = new BufferGeometry();
            var patternSolid = /solid([\s\S]*?)endsolid/g;
            var patternFace = /facet([\s\S]*?)endfacet/g;
            var faceCounter = 0;

            var patternFloat = /[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source;
            var patternVertex = new RegExp( 'vertex' + patternFloat + patternFloat + patternFloat, 'g' );
            var patternNormal = new RegExp( 'normal' + patternFloat + patternFloat + patternFloat, 'g' );

            var vertices = [];
            var normals = [];

            var normal = new Vector3();

            var result;

            var groupVertexes = [];
            var groupCount = 0;
            var startVertex = 0;
            var endVertex = 0;

            while ( ( result = patternSolid.exec( data ) ) !== null ) {

                startVertex = endVertex;

                var solid = result[ 0 ];

                while ( ( result = patternFace.exec( solid ) ) !== null ) {

                    var vertexCountPerFace = 0;
                    var normalCountPerFace = 0;

                    var text = result[ 0 ];

                    while ( ( result = patternNormal.exec( text ) ) !== null ) {

                        normal.x = parseFloat( result[ 1 ] );
                        normal.y = parseFloat( result[ 2 ] );
                        normal.z = parseFloat( result[ 3 ] );
                        normalCountPerFace ++;

                    }

                    while ( ( result = patternVertex.exec( text ) ) !== null ) {

                        vertices.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
                        normals.push( normal.x, normal.y, normal.z );
                        vertexCountPerFace ++;
                        endVertex ++;

                    }

                    // every face have to own ONE valid normal

                    if ( normalCountPerFace !== 1 ) {

                        console.error( 'THREE.STLLoader: Something isn\'t right with the normal of face number ' + faceCounter );

                    }

                    // each face have to own THREE valid vertices

                    if ( vertexCountPerFace !== 3 ) {

                        console.error( 'THREE.STLLoader: Something isn\'t right with the vertices of face number ' + faceCounter );

                    }

                    faceCounter ++;

                }

                groupVertexes.push( { startVertex: startVertex, endVertex: endVertex } );
                groupCount ++;

            }

            geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
            geometry.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );

            if ( groupCount > 0 ) {

                for ( var i = 0; i < groupVertexes.length; i ++ ) {

                    geometry.addGroup( groupVertexes[ i ].startVertex, groupVertexes[ i ].endVertex, i );

                }

            }

            return geometry;

        }

        function ensureString( buffer ) {

            if ( typeof buffer !== 'string' ) {

                return LoaderUtils.decodeText( new Uint8Array( buffer ) );

            }

            return buffer;

        }

        function ensureBinary( buffer ) {

            if ( typeof buffer === 'string' ) {

                var array_buffer = new Uint8Array( buffer.length );
                for ( var i = 0; i < buffer.length; i ++ ) {

                    array_buffer[ i ] = buffer.charCodeAt( i ) & 0xff; // implicitly assumes little-endian

                }

                return array_buffer.buffer || array_buffer;

            } else {

                return buffer;

            }

        }

        // start

        var binData = ensureBinary( data );

        return isBinary( binData ) ? parseBinary( binData ) : parseASCII( ensureString( data ) );

    }

};

export { STLLoader };

Some extra info:

The file data, when received by my frontend, looks like this: �u#;�O_?����W�Bt��B���A��B凪B�F�A���BJJ�BȧA�ۢ>#(q>�k?��B

I've been attempting to encode it as an ArrayBuffer using:

  var enc = new TextEncoder();
  var arrayBuffer = enc.encode(fileString).buffer;



from Load STL from buffer (not path) in Three.js

InversifyJS - Inject service to express middleware

I am using inversify, inversify-binding-decorators, and inversify-express-utlis and have problem with express middleware.

I am calling my middleware in this way:

let server = new InversifyExpressServer(container);
...
server.setConfig((app) => {

  app.use(validateSession);

});
...

This is my class for ioc registration. Please notice that here I manually register SessionContext in request scope

import DatabaseApi  from './../repositories/databaseApi';
import { Container, inject } from "inversify";
import TYPES from "./types";
import { autoProvide, makeProvideDecorator, makeFluentProvideDecorator } from "inversify-binding-decorators";
import { SessionContext } from './../services/session/sessionContext';
let container = new Container();
container.bind<SessionContext>(TYPES.SessionContext).to(SessionContext).inRequestScope();
let provide = makeProvideDecorator(container);
let fluentProvider = makeFluentProvideDecorator(container);

let provideNamed = (identifier: any, name: any) => {
  return fluentProvider(identifier)
    .whenTargetNamed(name)
    .done();
};



export { container, autoProvide, provide, provideNamed, inject };

Now in my middleware I want to get my SessionContext in request scope service in this way:

 export async function validateSession(req: Request, res: Response, next: NextFunction) {

  try {
    ...

    let sessionContext = container.get<SessionContext>(TYPES.SessionContext);

    ...
    return next();
  }
  catch (err) {
   next(err);
  }
}

Service is resolved, but the problem is that if I resolve him in other place I am getting other instance. In request scope doesn't work when I use service inside express middleware. Always resolve gives new instance here. In other words - I want to start scope from express middleware. What I feel is that scope starts later from inversify-express-utils controller.



from InversifyJS - Inject service to express middleware

force all page visits to refresh/clear cache after login/logout

My site is constructed entirely of dynamic data, some of which changes based on user authentication. When a user "logs in" to the site, I show their new status with their user name in the page navigation bar. However when they visit a page they visited recently before authenticating (back button, etc), that page's version of the navigation bar will not be refreshed. What are some methods to force a refreshed page to the browser? The inverse is also true: if a user logs out, recent pages will still show authenticated from the cached version.

What technique can I use to always force a browser-side refresh/clear cache on any page on the website?

Thanks.

Nb: server side I am using eXist-db 4.7's login:set-user() to authenticate a user (i.e. "log them in") through the controller.



from force all page visits to refresh/clear cache after login/logout

Badge count option in amazon SNS

I need to get badge count in my application. I am using amazon SNS service. Here is my code

AWS.config.update({
  accessKeyId: 'XXXXXXX',
  secretAccessKey: 'XXXXXXX'
})
AWS.config.update({ region: 'XXXXXXX' })
const sns = new AWS.SNS()
const params = {
  PlatformApplicationArn: 'XXXXXXX',
  Token: deviceToken
}
sns.createPlatformEndpoint(params, (err, EndPointResult) => {
  const client_arn = EndPointResult["EndpointArn"];
    sns.publish({
      TargetArn: client_arn,
      Message: message,
      Subject: title,
      // badge: 1
    }, (err, data) => {
    })
  })

I need to know where I can add badge option here?

Thank you!!!



from Badge count option in amazon SNS

Running LSTM with multiple GPUs gets "Input and hidden tensors are not at the same device"

I am trying to train a LSTM layer in pytorch. I am using 4 GPUs. When initializing, I added the .cuda() function move the hidden layer to GPU. But when I run the code with multiple GPUs I am getting this runtime error :

RuntimeError: Input and hidden tensors are not at the same device

I have tried to solve the problem by using .cuda() function in the forward function like below :

self.hidden = (self.hidden[0].type(torch.FloatTensor).cuda(), self.hidden[1].type(torch.FloatTensor).cuda()) 

This line seems to solve the problem, but it raises my concern that if the updated hidden layer is seen in different GPUs. Should I move the vector back to cpu at the end of the forward function for a batch or is there any other way to solve the problem.



from Running LSTM with multiple GPUs gets "Input and hidden tensors are not at the same device"

Trouble parsing tabular items from a graph located in a website

I'm trying to extract the tabular contents available on a graph in a webpage. The content of those tables are only visible when someone hovers his cursor within the area. One such table is this one.

Webpage address

The graph within which the tables are is titled as EPS consensus revisions : last 18 months.

I've tried so far with:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

link = "https://www.marketscreener.com/SUNCORP-GROUP-LTD-6491453/revisions/"

driver = webdriver.Chrome()
driver.get(link)
wait = WebDriverWait(driver, 10)
for items in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "#graphRevisionBNAeec span > table tr"))):
    data = [item.text for item in items.find_elements_by_css_selector("td")]
    print(data)
driver.quit()

When I run the above script, It throws thie error raise TimeoutException(message, screen, stacktrace):selenium.common.exceptions.TimeoutException: Message: pointing at this for items in wait.until() line.

Output from a single table out of many should look like:

Period: Thursday, Aug 22, 2019
Number of upgrading estimates: 0
Number of unchanged estimates: 7
Number of Downgrading estimates: 0
High Value: 0.90 AUD
Mean Value: 0.85 AUD
Low Value: 0.77 AUD

How can I get the content of those tables from that graph?



from Trouble parsing tabular items from a graph located in a website

What to do when object on realm gets invalidated

In my iOS app I am using the Realm library for storing data. It works great, until for one reason or the other, object get invalidated. (reasons in the specific case could be that I sometimes implement background jobs on the same data that are getting visualized on view, or similar scenarios).

I know why it happens, and I understand is correct behavior but from there on: what is the correct behavior I should implement?

I would love to pull the data from Realm again and continue my job, but when an object gets invalidated, every field is inaccessible and crashes the environment (so, I don't know what is the unique+immutable id of the object).

How can I safely pull the current data from that object again, without storing the id in the ViewController?

Here is some code. I had to edit it heavily to since the structure of the app is different, but the issue is still exemplified. Assume that the table view delegate's is the view and all the technicalities are there.

// A class variable
var events: RLMResults<RLMMyEvent>
// A table view that shows all "MyEvents"
var tableview: UITableView

func initialiseView(_ predicate: NSPredicate) {
  // Get the events with a predicate from Realm
  events = RLMMyEvent.objects(with: predicate)
  tableview.reloadData()
}

// All tableView delegates, and in particular

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as! MyCell

   let event = self.events[UInt(indexPath.row)]

   if !event.isInvalidated {
   } else {

   /***** HERE is the problem. What to do here?
          HOW to get those data again, since I cannot 
          get that event's unique ID?  ****/
   }
   cell.initialize(event)
   return cell
}



from What to do when object on realm gets invalidated

Directus can't be installed on a shared hosting

I'm trying to setup Directus.

I just performed a brand new install following the guidelines described in the documentation. However once I login, I have this error: "Server Error - Something is wrong with this instance’s server or database."

A UI would be expected instead with this message: "No Collections Setup - It seems like there aren't any collections setup yet"

The installation works fine on localhost with WAMP, so I suspect that something on the shared host or the database is misconfigured.

According to the console, many resources cannot be reached:

  • 404: /_/users/me?fields=last_page:1
  • 401: /interfaces:1
  • 401: /layouts:1
  • 401: /pages:1
  • 403: /_/collections:1
  • 403: /_/settings:1
  • 401: (API root)
  • 403: /_/collection_preset...
  • 403: /_/users?field...
  • 403: /_/relations?limit=1

MySQL version (5.7) and PHP version (7.3) meet the requirements for Directus...

I really don't know what to look for to diagnose any compatibility issue with the shared hosting...


EDIT

Here is the log (without the stacks):

[2019-08-28 11:31:24] api[_].ERROR: Directus\Database\Exception\ItemNotFoundException: Item not found in [server root path]/directus/src/core/Directus/Services/ItemsService.php:139
[2019-08-28 11:31:29] api[_].ERROR: Directus\Database\Exception\ItemNotFoundException: Item not found in [server root path]/directus/src/core/Directus/Services/ItemsService.php:139
[2019-08-28 11:31:29] api[].ERROR: Directus\Exception\UnauthorizedException: Unauthorized request in [server root path]/directus/src/helpers/app.php:268
[2019-08-28 11:31:29] api[].ERROR: Directus\Exception\UnauthorizedException: Unauthorized request in [server root path]/directus/src/helpers/app.php:268
[2019-08-28 11:31:29] api[_].ERROR: Directus\Permissions\Exception\ForbiddenCollectionReadException: Reading items from "directus_collections" collection was denied in [server root path]/directus/src/core/Directus/Permissions/Acl.php:988
[2019-08-28 11:31:29] api[_].ERROR: Directus\Permissions\Exception\ForbiddenCollectionReadException: Reading items from "directus_settings" collection was denied in [server root path]/directus/src/core/Directus/Permissions/Acl.php:988
[2019-08-28 11:31:29] api[].ERROR: Directus\Exception\UnauthorizedException: Unauthorized request in [server root path]/directus/src/helpers/app.php:268
[2019-08-28 11:31:29] api[_].ERROR: Directus\Permissions\Exception\ForbiddenCollectionReadException: Reading items from "directus_collection_presets" collection was denied in [server root path]/directus/src/core/Directus/Permissions/Acl.php:988
[2019-08-28 11:31:29] api[].ERROR: Directus\Exception\UnauthorizedException: Unauthorized request in [server root path]/directus/src/helpers/app.php:268
[2019-08-28 11:31:29] api[_].ERROR: Directus\Permissions\Exception\ForbiddenCollectionReadException: Reading items from "directus_relations" collection was denied in [server root path]/directus/src/core/Directus/Permissions/Acl.php:988
[2019-08-28 11:31:29] api[_].ERROR: Directus\Permissions\Exception\ForbiddenCollectionReadException: Reading items from "directus_collection_presets" collection was denied in [server root path]/directus/src/core/Directus/Permissions/Acl.php:988
[2019-08-28 11:31:29] api[_].ERROR: Directus\Permissions\Exception\ForbiddenCollectionReadException: Reading items from "directus_users" collection was denied in [server root path]/directus/src/core/Directus/Permissions/Acl.php:988



from Directus can't be installed on a shared hosting

Whats the difference between JS Number.MAX_SAFE_INTEGER and MAX_VALUE?

Number.MAX_SAFE_INTEGER 9007199254740991

Number.MAX_VALUE 1.7976931348623157e+308

I understand how MAX_SAFE_INTEGER is computed based on JavaScript's double precision floating point arithmetic, but where does this huge max value come from? Is it the number that comes about if you're using all 63 bits for the exponent instead of the safe 11 bits?



from Whats the difference between JS Number.MAX_SAFE_INTEGER and MAX_VALUE?

Paypal send shipping country (use different values lc and country fields)

I try to integrate a paypal button payment on my website. The website accepts users from many countries. The website's language are english. My users defines shipping address in my website and I provide it to Paypal with the form. But, when I sent another country without change lc paramter, Paypal don't pre-fill country with the new.

My Problem is the opposit of this one : Paypal Hosted language bug. Based on 'country' instead of 'lc' for Paypal Express button

Example (my form) :

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

    <input type="hidden" name="amount" value="5">
    <input name="currency_code" type="hidden" value="GBP">
    <input name="shipping" type="hidden" value="0.00">
    <input name="tax" type="hidden" value="0.00">
    <input name="return" type="hidden" value="https://my-shop.com">
    <input name="cancel_return" type="hidden" value="https://my-shop.com">
    <input name="notify_url" type="hidden" value="https://my-shop.com">
    <input name="cmd" type="hidden" value="_xclick">
    <input name="business" type="hidden" value="sales@my-shop.com">
    <input name="no_shipping" type="hidden" value="1">
    <input name="item_name" type="hidden" value="1234">
    <input name="no_note" type="hidden" value="1">
    <input name="bn" type="hidden" value="xxxx">
    <input name="custom" type="hidden" value="the_buyer@gmail.com">
    <input name="invoice" type="hidden" value="1223">

    <input name="address_override" type="hidden" value="1">
    <input name="address1" type="hidden" value="Frani Sramka 20">
    <input name="address2" type="hidden" value="">
    <input name="city" type="hidden" value="Prague 5">
    <input name="zip" type="hidden" value="15000">
    <input name="country" type="hidden" value="CZ">

    <!-- Countries part -->
    <input name="lc" type="hidden" value="GB">

    <input name="address_country" type="hidden" value="CZECH REPUBLIC">
    <input name="address_country_code" type="hidden" value="CZ">
    <input name="residence_country" type="hidden" value="CZ">


    <button type="submit" class="btn btn-primary">Pay by PayPal</button>
</form>

In this case, Paypal set the page language in GB (provided by lc field) But the Paypal's Country field was pre-fill with United Kingdom, see screenshot :

enter image description here

But I want Paypal take my countries fields (with value CZ) into account.


Set lc field to CZ behavior

If I set lc field to CZ :

<input name="lc" type="hidden" value="CZ">

I get both language in CZ and user country pre-fill in CZ :

enter image description here


Brief question :

Do you know a way to :

  • Pre-fill user country (CZ)
  • Keep the choosen language (GB)

Additional information

  • Except this language issue, the form works
  • I use a custom PHP back-end technology (not a CMS with plugin)

Paypal Documentation

pre-populate my customer's PayPal sign-up form, contains country and lc description

Countries code



from Paypal send shipping country (use different values lc and country fields)

Ionic 4 / Angular - validation highlight extends past the native input field

When adding user input to an input form of a set width, the underline extends beyond the bounds of the input.

underline validation extending beyond input

Given the following code:

<ion-list lines="none">
  <ion-item>
     <ion-label color="medium" position="floating">Username</ion-label>
     <ion-input type="text" formControlName="username" autocomplete="username"></ion-input>
          </ion-item>
        <ion-text
            color="danger"
            [hidden]="loginForm.controls.username.valid || loginForm.controls.username.untouched"
          >
            <span padding>Valid email is required</span>
        </ion-text>
        <ion-item>
          <ion-label color="medium" position="floating">Password</ion-label>
          <ion-input type="password" formControlName="password" autocomplete="current-password"></ion-input>
        </ion-item>
        <ion-text
            color="danger"
            [hidden]="loginForm.controls.password.valid || loginForm.controls.password.untouched"
          >
            <span padding translate>Password is required</span>
        </ion-text>
        <a href="/login/forgot" class="forgot-password ion-float-right">
            [Forgot Your Password?]
        </a>
     </ion-list>

Additionally, when I tab onto a field, the INPUT covers the entire ion-item field, rather than the ion-input field, as shown below:

enter image description here

I've tried a various set of changes to the css with no great success. Via inspector, I am able to get rid of the issue by changing the --inset-padding-end variable to 0, but I have not found out how to change / set that globally?

Are there any quick-fixes for this that anybody knows of? This error is especially bad-looking when the ion-list is set to "inset", as shown below:

enter image description here



from Ionic 4 / Angular - validation highlight extends past the native input field

Ionic 4 / Angular - validation highlight extends past the native input field

When adding user input to an input form of a set width, the underline extends beyond the bounds of the input.

underline validation extending beyond input

Given the following code:

<ion-list lines="none">
  <ion-item>
     <ion-label color="medium" position="floating">Username</ion-label>
     <ion-input type="text" formControlName="username" autocomplete="username"></ion-input>
          </ion-item>
        <ion-text
            color="danger"
            [hidden]="loginForm.controls.username.valid || loginForm.controls.username.untouched"
          >
            <span padding>Valid email is required</span>
        </ion-text>
        <ion-item>
          <ion-label color="medium" position="floating">Password</ion-label>
          <ion-input type="password" formControlName="password" autocomplete="current-password"></ion-input>
        </ion-item>
        <ion-text
            color="danger"
            [hidden]="loginForm.controls.password.valid || loginForm.controls.password.untouched"
          >
            <span padding translate>Password is required</span>
        </ion-text>
        <a href="/login/forgot" class="forgot-password ion-float-right">
            [Forgot Your Password?]
        </a>
     </ion-list>

Additionally, when I tab onto a field, the INPUT covers the entire ion-item field, rather than the ion-input field, as shown below:

enter image description here

I've tried a various set of changes to the css with no great success. Via inspector, I am able to get rid of the issue by changing the --inset-padding-end variable to 0, but I have not found out how to change / set that globally?

Are there any quick-fixes for this that anybody knows of? This error is especially bad-looking when the ion-list is set to "inset", as shown below:

enter image description here



from Ionic 4 / Angular - validation highlight extends past the native input field

Scrapy does not fetch markup on response.css

I've built a simple scrapy spider running on scrapinghub:

class ExtractionSpider(scrapy.Spider):
    name = "extraction"
    allowed_domains = ['domain']
    start_urls = ['http://somedomainstart']
    user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"

    def parse(self, response):
        urls = response.css('a.offer-details__title-link::attr(href)').extract()

        print(urls)
        for url in urls:
            url = response.urljoin(url)
            yield SplashRequest(url=url, callback=self.parse_details)

        multiple_locs_urls = response.css('a.offer-regions__label::attr(href)').extract()
        print(multiple_locs_urls)        
        for url in multiple_locs_urls:
            url = response.urljoin(url)
            yield SplashRequest(url=url, callback=self.parse_details)

        next_page_url = response.css('li.pagination_element--next > a.pagination_trigger::attr(href)').extract_first()
        if next_page_url:
            next_page_url = response.urljoin(next_page_url)
            yield SplashRequest(url=next_page_url, callback=self.parse)

    def parse_details(self, response): 
        yield {
        'title': response.css('#jobTitle').extract_first(),
        'content': response.css('#description').extract_first(),
        'datePosted': response.css('span[itemprop="datePosted"]').extract_first(),
        'address': response.css('span[itemprop="address"]').extract_first()
        }

The problem I am facing is that the multiple_locs_url response.css returns an empty array despite me seeing it in the markup on the browser side.

I checked with scrapy shell and scrapy shell does not see the markup. I guess this is due to the markup being rendered through javascript when the page is loaded.

I added splash but that does not seem to apply to response. How would I make scrapy wait with the query until the page is loaded?



from Scrapy does not fetch markup on response.css

Align bitmap in Android OpenGL Es - ArCore

I'm using Google sample https://developers.google.com/ar/develop/java/augmented-images/ and I want to modify it so it will be able to display bitmap over AugumentedImage.

Currently I'm able to display bitmap on android.opengl.GLSurfaceView but I have no idea how to position it so it will match visible augumented image.

The way I'm displaying bitmap


class BitmapRenerer {
    private static final String TAG = BitmapRenerer.class.getSimpleName();
    //Reference to Activity Context
    private final Context context;

    //Added for Textures
    private final FloatBuffer cubeTextureCoordinates;
    private int textureDataHandle;


    private final int shaderProgram;
    private final FloatBuffer vertexBuffer;
    private final ShortBuffer drawListBuffer;

    // number of coordinates per vertex in this array
    private static final int COORDS_PER_VERTEX = 2;
    private static float[] spriteCoords = {
            -0.15f, 0.15f,   // top left
            -0.15f, -0.15f,   // bottom left
            0.15f, -0.15f,   // bottom right
            0.15f, 0.15f}; //top right

    private short[] drawOrder = {0, 1, 2, 0, 2, 3}; // order to draw vertices

    // Set color with red, green, blue and alpha (opacity) values
    private float[] color = {1f, 1f, 1f, 1.0f};


    BitmapRenerer(final Context activityContext) throws IOException {
        context = activityContext;

        //Initialize Vertex Byte Buffer for Shape Coordinates / # of coordinate values * 4 bytes per float
        ByteBuffer bb = ByteBuffer.allocateDirect(spriteCoords.length * 4);
        //Use the Device's Native Byte Order
        bb.order(ByteOrder.nativeOrder());
        //Create a floating point buffer from the ByteBuffer
        vertexBuffer = bb.asFloatBuffer();
        //Add the coordinates to the FloatBuffer
        vertexBuffer.put(spriteCoords);
        //Set the Buffer to Read the first coordinate
        vertexBuffer.position(0);


        final float[] cubeTextureCoordinateData = {
                0.0f, 0.0f, // top left
                0.0f, 1.0f, // Top-right
                1.0f, 1.0f, // Bottom-right
                1.0f, 0.0f // Bottom-left
        };
        cubeTextureCoordinates = ByteBuffer.allocateDirect(cubeTextureCoordinateData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
        cubeTextureCoordinates.put(cubeTextureCoordinateData).position(0);

        //Initialize byte buffer for the draw list
        ByteBuffer dlb = ByteBuffer.allocateDirect(spriteCoords.length * 2);
        dlb.order(ByteOrder.nativeOrder());
        drawListBuffer = dlb.asShortBuffer();
        drawListBuffer.put(drawOrder);
        drawListBuffer.position(0);


        int vertexShader = ShaderUtil.loadGLShader(TAG, activityContext, GLES20.GL_VERTEX_SHADER, "shaders/bitmap/vertex_shader.vert");
        int fragmentShader = ShaderUtil.loadGLShader(TAG, activityContext, GLES20.GL_FRAGMENT_SHADER, "shaders/bitmap/vertex_shader.frag");

        shaderProgram = GLES20.glCreateProgram();
        GLES20.glAttachShader(shaderProgram, vertexShader);
        GLES20.glAttachShader(shaderProgram, fragmentShader);

        //Texture Code
        GLES20.glBindAttribLocation(shaderProgram, 0, "a_TexCoordinate");
        GLES20.glLinkProgram(shaderProgram);


        //Load the texture
        textureDataHandle = loadTexture(context);
    }

    public void draw(float[] mvpMatrix) {

        //Add program to OpenGL ES Environment
        GLES20.glUseProgram(shaderProgram);

        //Get handle to vertex shader's vPosition member
        int mPositionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition");
        //Enable a handle to the triangle vertices
        GLES20.glEnableVertexAttribArray(mPositionHandle);
        //Prepare the triangle coordinate data
        //Bytes per vertex
        int vertexStride = COORDS_PER_VERTEX * 4;
        GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
        //Get Handle to Fragment Shader's vColor member
        int mColorHandle = GLES20.glGetUniformLocation(shaderProgram, "vColor");
        //Set the Color for drawing the triangle
        GLES20.glUniform4fv(mColorHandle, 1, color, 0);
        //Set Texture Handles and bind Texture
        int textureUniformHandle = GLES20.glGetAttribLocation(shaderProgram, "u_Texture");
        int textureCoordinateHandle = GLES20.glGetAttribLocation(shaderProgram, "a_TexCoordinate");
        //Set the active texture unit to texture unit 0.
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        //Bind the texture to this unit.
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureDataHandle);
        //Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0.
        GLES20.glUniform1i(textureUniformHandle, 0);
        //Pass in the texture coordinate information
        cubeTextureCoordinates.position(0);
        int textureCoordinateDataSize = 2;
        GLES20.glVertexAttribPointer(textureCoordinateHandle, textureCoordinateDataSize, GLES20.GL_FLOAT, false, 0, cubeTextureCoordinates);
        GLES20.glEnableVertexAttribArray(textureCoordinateHandle);
        //Get Handle to Shape's Transformation Matrix
        int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix");
        //Apply the projection and view transformation
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);

        // try

        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);


        //

        GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        //transpaency du bitmap+text !!!
        GLES20.glEnable(GLES20.GL_BLEND);
        GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        //draw the triangle
        GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
        //Disable Vertex Array
        GLES20.glDisableVertexAttribArray(mPositionHandle);


    }

    public int loadTexture(final Context context) {
        final int[] textureHandle = new int[1];
        GLES20.glGenTextures(1, textureHandle, 0);
        if (textureHandle[0] != 0) {
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inScaled = false;   // No pre-scaling
            options.inMutable = true;

            // Bind to the texture in OpenGL
            Bitmap bitmap = drawTextToBitmap();
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
            // Set filtering
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

            // Load the bitmap into the bound texture.
            GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
            // GLUtils.texImage2D(GLES20. GL_UNSIGNED_SHORT_5_5_5_1,0, bitmap, 0);
            // GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA,256,256, 0, GLES20.GL_RGBA,GLES20.GL_UNSIGNED_BYTE,textureHandle[0]);
            // Recycle the bitmap, since its data has been loaded into OpenGL.
            bitmap.recycle();


        }
        if (textureHandle[0] == 0) {
            throw new RuntimeException("Error loading texture.");
        }
        return textureHandle[0];
    }


    void setCoords(float a1, float a2, float b1, float b2, float c1, float c2, float d1, float d2) {
        spriteCoords[0] = a1;
        spriteCoords[1] = a2;
        spriteCoords[2] = b1;
        spriteCoords[3] = b2;
        spriteCoords[4] = c1;
        spriteCoords[5] = c2;
        spriteCoords[6] = d1;
        spriteCoords[7] = d2;
        ByteBuffer bb = ByteBuffer.allocateDirect(
                // (# of coordinate values * 4 bytes per float)
                spriteCoords.length * 4);
        bb.order(ByteOrder.nativeOrder());
        vertexBuffer.put(spriteCoords);
        vertexBuffer.position(0);
        // initialize byte buffer for the draw list
        ByteBuffer dlb = ByteBuffer.allocateDirect(
                // (# of coordinate values * 2 bytes per short)
                drawOrder.length * 2);
        dlb.order(ByteOrder.nativeOrder());
        drawListBuffer.put(drawOrder);
        drawListBuffer.position(0);
    }

    private Bitmap drawTextToBitmap() {
        Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
        // get a canvas to paint over the bitmap
        Canvas canvas = new Canvas(bitmap);
        bitmap.eraseColor(android.graphics.Color.TRANSPARENT);

        canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);


        TextPaint textPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setAntiAlias(true);
        textPaint.setColor(Color.RED);
        textPaint.setTextSize(30);

        TextView tv = new TextView(context);
        tv.setTextColor(Color.RED);
        tv.setTextSize(10);

        String text = "DEMO TEXT DEMO";
        tv.setTextSize(10f);
        tv.setText(text);
        tv.setEllipsize(TextUtils.TruncateAt.END);
        tv.setMaxLines(4);
        tv.setGravity(Gravity.BOTTOM);
        tv.setPadding(8, 8, 8, 50);
        tv.setDrawingCacheEnabled(true);
        tv.measure(View.MeasureSpec.makeMeasureSpec(canvas.getWidth(),
                View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(
                canvas.getHeight(), View.MeasureSpec.EXACTLY));
        tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());


        LinearLayout parent = null;
        if (bitmap != null && !bitmap.isRecycled()) {
            parent = new LinearLayout(context);
            parent.setBackgroundColor(Color.GRAY);
            parent.setDrawingCacheEnabled(true);
            parent.measure(View.MeasureSpec.makeMeasureSpec(canvas.getWidth(),
                    View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(
                    canvas.getHeight(), View.MeasureSpec.EXACTLY));
            parent.layout(0, 0, parent.getMeasuredWidth(),
                    parent.getMeasuredHeight());

            parent.setLayoutParams(new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
            parent.setOrientation(LinearLayout.VERTICAL);


            parent.setBackgroundColor(Color.GRAY);
//            parent.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));


            parent.addView(tv);

        } else {
            // write code to recreate bitmap from source
            // Write code to show bitmap to canvas
        }

        canvas.drawBitmap(parent.getDrawingCache(), 0, 0, textPaint);

        tv.setDrawingCacheEnabled(false);
        parent.setDrawingCacheEnabled(false);

        return bitmap;

    }
}

I know that I have to pass proper coords in this class, but I have no idea how to obtain them. I know that augmentedImage.getCenterPose() might be useful in this case, but I have no idea how to map this data so it will be usable for void setCoords(float a1, float a2, float b1, float b2, float c1, float c2, float d1, float d2) method.



from Align bitmap in Android OpenGL Es - ArCore

Iterating through specific columns and rows in pandas dataframe to perform a check

I have this data:

I need to perform a check in which for example in the yellow row I highlighted the StepRate2 is 3 and then StepRate3 is 2, when this happens I will have a new column called 'Step Check' with an 'X' for that row. Essentially we cannot have StepRates that all of a sudden go down.

I am totally new to Python and I need help on this. The output should look like this

Here is a copy of the data in a table

    StepDate1   StepRate1   StepDate2   StepRate2   StepDate3   StepRate3   StepDate4   StepRate4   StepDate5   StepRate5   StepDate6   StepRate6
    8/1/2011     2       8/1/2016       3        8/1/2017         4      8/1/2018      4.5       8/1/2020      4.5           0
    11/1/2014    2      11/1/2017      3        11/1/2018         4     
11/1/2019        5      11/1/2020      5.38          0
    5/1/2015     2       5/1/2018      3        9/1/2018          2      3/1/2019        3       3/1/2020      3.66          0
    11/1/2015    3.92    9/1/2018      3.92    11/1/2018          4.92  11/1/2019        4.92   11/1/2020      4.92    11/1/2021          6.75
    8/1/2014     2.5    8/1/2017       3.5      8/1/2018          4.5    8/1/2019        5.5    8/1/2020       6.5           0
    6/1/2010     2      6/1/2014       3        6/1/2015          4      6/1/2016        5      6/1/2020       5             0

Here is what I want the sample output to be

StepDate1   StepRate1   StepDate2   StepRate2   StepDate3   StepRate3   StepDate4   StepRate4   StepDate5   StepRate5   StepDate6   StepRate6   Step Check
8/1/2011    2   8/1/2016    3   8/1/2017    4   8/1/2018    4.5 8/1/2020    4.5     0   
11/1/2014   2   11/1/2017   3   11/1/2018   4   11/1/2019   5   11/1/2020   5.38        0   
5/1/2015    2   5/1/2018    3   9/1/2018    2   3/1/2019    3   3/1/2020    3.66        0   X
11/1/2015   3.92    9/1/2018    3.92    11/1/2018   4.92    11/1/2019   4.92    11/1/2020   4.92    11/1/2021   6.75    
8/1/2014    2.5 8/1/2017    3.5 8/1/2018    4.5 8/1/2019    5.5 8/1/2020    6.5     0   
6/1/2010    2   6/1/2014    3   6/1/2015    4   6/1/2016    5   6/1/2020    5       0   

Here is sample data:

{'StepRate1': {0: nan, 1: nan, 2: nan, 3: nan, 4: 8.45, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan, 10: nan, 11: nan, 12: nan, 13: nan, 14: nan, 15: nan, 16: nan, 17: nan, 18: nan, 19: nan, 20: nan, 21: nan, 22: nan, 23: nan, 24: nan, 25: nan, 26: nan, 27: nan, 28: nan, 29: nan, 30: nan, 31: nan, 32: nan, 33: nan, 34: nan, 35: nan, 36: nan, 37: nan, 38: nan, 39: nan, 40: nan, 41: nan, 42: nan, 43: 6.0, 44: nan, 45: nan, 46: nan, 47: nan, 48: nan, 49: nan, 50: nan, 51: nan, 52: nan, 53: nan, 54: nan, 55: nan, 56: nan, 57: nan, 58: nan, 59: nan, 60: nan, 61: nan, 62: nan, 63: nan, 64: nan, 65: nan, 66: nan, 67: nan, 68: nan, 69: nan, 70: nan, 71: nan, 72: nan, 73: nan, 74: nan, 75: nan, 76: nan, 77: nan, 78: nan, 79: nan, 80: nan, 81: nan, 82: nan, 83: nan, 84: 3.75, 85: nan, 86: nan, 87: nan, 88: nan, 89: nan, 90: nan, 91: nan, 92: 4.75, 93: 3.0, 94: nan, 95: nan, 96: nan, 97: nan, 98: nan, 99: nan, 100: nan, 101: nan, 102: 4.7824, 103: nan, 104: nan, 105: 3.0, 106: nan, 107: nan, 108: nan, 109: nan, 110: nan, 111: nan, 112: nan, 113: nan, 114: nan, 115: nan, 116: nan, 117: nan, 118: 3.0, 119: nan, 120: 6.03, 121: nan, 122: nan, 123: 3.0, 124: 3.5, 125: 3.0, 126: nan, 127: nan, 128: nan, 129: nan, 130: 4.0, 131: 2.0, 132: nan, 133: nan, 134: 4.0, 135: 4.0, 136: 2.0, 137: nan, 138: nan, 139: nan, 140: nan, 141: 4.75, 142: 2.125, 143: 4.2, 144: 4.75, 145: 3.26, 146: nan, 147: 4.375, 148: 9.33, 149: 5.0, 150: nan, 151: 7.1, 152: nan, 153: 4.0, 154: 5.74, 155: 3.35, 156: nan, 157: nan, 158: nan, 159: 2.0, 160: nan, 161: 4.0, 162: nan, 163: nan, 164: nan, 165: 6.0, 166: 4.5, 167: 2.0, 168: nan, 169: nan, 170: nan, 171: nan, 172: 2.375, 173: nan, 174: nan, 175: nan, 176: 6.0, 177: nan, 178: nan, 179: 2.0, 180: nan, 181: nan, 182: nan, 183: nan, 184: nan, 185: nan, 186: 4.5, 187: nan, 188: 4.0, 189: nan, 190: nan, 191: nan, 192: nan, 193: nan, 194: nan, 195: 4.5, 196: 1.0, 197: nan, 198: nan, 199: 7.0, 200: nan, 201: 4.0, 202: nan, 203: nan, 204: nan, 205: nan, 206: nan, 207: nan, 208: nan, 209: nan,
210: nan, 211: 2.0, 212: nan, 213: nan, 214: 4.5, 215: nan, 216: 5.125, 217: 2.0, 218: nan, 219: nan, 220: nan, 221: nan, 222: nan, 223: 1.0, 224: 5.6, 225: 4.65, 226: nan, 227: nan, 228: nan, 229: 11.88, 230: 4.75, 231: 2.0, 232: 4.0, 233: nan, 234: nan, 235: nan, 236: 3.5, 237: nan, 238: nan, 239: nan, 240: nan, 241: nan, 242: nan, 243: nan, 244: nan, 245: nan, 246: nan, 247: 5.5, 248: nan, 249: nan, 250: nan, 251: nan, 252: nan, 253: 3.25, 254: nan, 255: nan, 256: nan, 257: nan, 258: nan, 259: nan, 260: nan, 261: 3.0, 262: nan, 263: 5.5, 264:
6.0, 265: nan, 266: nan, 267: nan, 268: nan, 269: 2.0, 270: nan, 271: nan, 272: 5.49, 273: nan, 274: 5.2, 275: nan, 276: nan, 277: 2.0, 278: 2.0, 279: 2.0, 280: 3.0, 281: nan, 282: 2.0, 283: 2.0, 284: 3.0, 285: nan, 286: nan, 287: 3.0, 288: 2.0, 289: nan, 290: nan, 291: nan, 292: nan, 293: 3.375, 294: nan, 295: 2.0, 296: 2.0, 297: 2.0, 298: nan, 299: 2.0, 300: 4.125, 301: nan, 302: 2.0, 303: nan, 304: 3.0, 305: nan, 306: 3.625, 307: nan, 308: nan, 309: nan, 310: nan, 311: nan, 312: nan, 313: 4.375, 314: nan, 315: nan, 316: nan, 317: nan, 318: 3.375, 319: nan, 320: 2.0, 321: nan, 322: nan, 323: nan, 324: nan, 325: nan, 326: nan, 327: nan, 328: nan, 329: 3.125, 330: nan, 331: nan, 332: nan, 333: nan, 334: nan, 335: nan, 336: nan, 337: nan, 338: nan, 339: nan, 340: nan, 341: 4.0, 342: nan, 343: nan, 344: nan, 345: nan, 346: nan, 347: nan, 348: nan, 349: nan, 350: 2.0, 351: nan, 352: nan, 353: nan, 354: 3.125,
355: nan, 356: nan, 357: nan, 358: 3.0, 359: 2.0, 360: 2.0, 361: nan, 362: 2.0, 363: nan, 364: nan, 365: 2.0, 366: nan, 367: nan, 368: nan, 369: nan, 370: 2.75, 371: nan, 372: nan, 373: nan, 374: nan, 375: nan, 376: nan, 377: nan, 378: 2.0, 379: 4.25, 380: nan, 381: nan, 382: 3.0, 383: nan, 384: 3.75, 385: nan, 386: nan, 387: nan, 388: nan, 389: 3.375, 390: nan, 391: nan, 392: nan, 393: nan, 394: 3.5, 395: 3.375, 396: nan, 397: 3.25, 398: nan, 399: nan, 400: nan, 401: nan, 402: nan, 403: nan, 404: nan, 405: 2.0, 406: nan, 407: nan, 408: nan, 409: nan, 410: 2.0, 411: nan, 412: nan, 413: nan, 414: nan, 415: 3.0, 416: nan, 417: 3.0, 418: nan, 419: nan, 420: 3.375, 421: nan, 422: 2.0, 423: nan, 424: nan, 425: nan, 426: nan, 427: nan, 428: nan, 429: nan, 430: nan, 431: 7.5, 432: nan, 433: 5.25, 434: nan, 435: nan, 436: 3.0, 437: 4.24, 438: nan, 439: nan, 440: nan, 441: nan, 442: nan, 443: 5.0, 444: nan, 445: nan, 446: 5.625, 447: nan, 448: nan, 449: 3.5, 450: nan, 451: 2.0, 452: nan, 453: nan, 454: 2.75, 455: 2.0, 456: nan, 457: nan, 458: 2.0, 459: nan, 460: nan, 461: 2.0, 462: nan, 463: 2.0, 464: 2.0, 465: nan, 466: nan, 467: nan, 468: 2.0, 469: 2.0, 470: nan, 471: nan, 472: 2.375, 473: 2.0, 474: 2.875, 475: 3.362, 476: nan, 477: 2.125, 478: 0.125, 479: 2.0, 480: nan, 481: nan, 482: nan, 483: 2.0, 484: nan, 485: nan, 486: nan, 487: nan, 488: nan, 489: nan, 490: nan, 491: 4.0, 492: nan, 493: nan, 494: nan, 495: nan, 496: 0.75, 497: nan, 498: 2.0, 499: nan, 500: nan, 501: nan, 502: nan, 503: nan, 504: 8.14, 505: nan, 506: 3.125, 507: nan, 508: nan, 509: 4.0, 510: nan, 511: nan, 512: nan, 513: nan, 514: nan, 515: 2.0, 516: nan, 517: 4.0, 518: nan, 519: nan, 520: 2.0, 521: nan, 522: nan, 523: nan, 524: nan, 525: 2.0, 526: 2.0, 527: nan, 528: nan, 529: nan, 530: nan, 531: nan, 532: nan, 533: nan, 534: nan, 535: 2.0, 536: nan, 537: 2.0, 538: nan, 539: 2.0, 540: nan, 541: 3.0, 542: nan, 543: nan, 544: 2.0, 545: nan, 546: nan, 547: 2.0, 548: 3.0, 549: 2.0, 550: nan, 551: 2.0, 552: 3.0, 553: nan, 554:
nan, 555: nan, 556: nan, 557: nan, 558: 2.0, 559: 2.0, 560: nan, 561: nan, 562: 2.0, 563: nan, 564: nan, 565: 2.875, 566: 2.0, 567: 2.0, 568: nan, 569: 1.5, 570: 2.0, 571: 2.0, 572: nan, 573: nan, 574: 2.0, 575: 2.0, 576: nan, 577: 3.0, 578: nan, 579: 2.0, 580: nan, 581: 2.875, 582: 2.0, 583: 2.25, 584: nan, 585: nan, 586: nan, 587: nan, 588: 2.0, 589: nan, 590: nan, 591: 2.625, 592: 2.0, 593: 2.0, 594: nan, 595: 3.0, 596: nan, 597: nan, 598: nan, 599: nan, 600: 6.375, 601: nan, 602: nan, 603: nan, 604: 2.0, 605: 2.0, 606: 2.0, 607: 2.905, 608: 4.219, 609: nan, 610: 2.0, 611: 3.042, 612: nan, 613: 2.003, 614: 2.0, 615: 2.0, 616: 2.0, 617: 3.282, 618: nan, 619: 5.087, 620: nan, 621: nan, 622: nan, 623: nan, 624: 5.859, 625: nan, 626: 2.551, 627: nan, 628: 3.242, 629: nan, 630: nan, 631: 2.0, 632: 2.114, 633: 3.456, 634: 2.0, 635: nan, 636: 5.06, 637: 5.671, 638: 3.63, 639: nan, 640: nan, 641: 5.144, 642: 2.511, 643: 2.573, 644: nan, 645: nan, 646: 4.09, 647: nan, 648: 2.03, 649: 3.92, 650: 2.922, 651: 3.145, 652: nan, 653: nan, 654: 5.166, 655: nan, 656: 2.5, 657: nan, 658: 2.0, 659: nan, 660: 5.483, 661: nan, 662: nan, 663: nan, 664: nan, 665: 2.0, 666: nan, 667: 2.0, 668: 3.961, 669: 6.04, 670: 4.672, 671: 2.0, 672: 2.0, 673: nan, 674: 2.695, 675: nan, 676: 2.0, 677: nan, 678: 5.226, 679: nan, 680: 2.595, 681: nan, 682: 2.0, 683: nan, 684: nan, 685: nan, 686: nan, 687: 5.27, 688: nan, 689: 3.625, 690: 5.25, 691: 2.0, 692: 5.0, 693: nan, 694: 3.532, 695: 3.51, 696: 2.578, 697: 4.84, 698: 4.26, 699: 4.62, 700: 6.09, 701: nan, 702: nan, 703: 2.0, 704: nan, 705: nan, 706: nan, 707: 6.68, 708: 3.0, 709: 3.0, 710: nan, 711: nan, 712: nan, 713: 2.0, 714: 4.972, 715: 2.0, 716: 2.0, 717: 3.0, 718: 3.375, 719: nan, 720: 3.5, 721: nan, 722: 3.125, 723: 4.0, 724: nan, 725: 3.625, 726: nan, 727: 3.18, 728: 4.0, 729: 2.0, 730: 3.375, 731: 3.302, 732: 2.0, 733: nan, 734: 2.193, 735: 2.0, 736: nan, 737: nan, 738: nan, 739: nan, 740: nan, 741: nan, 742: 2.0, 743: nan, 744: 2.25, 745: 2.0, 746: 2.23, 747:
2.0, 748: 3.375, 749: 3.0, 750: 2.125, 751: nan, 752: 2.999, 753: nan, 754: nan, 755: nan, 756: nan, 757: nan, 758: nan, 759: 2.43, 760: 4.875, 761: 3.868, 762: 3.847, 763: 2.0, 764: 2.441, 765: 2.0, 766: nan, 767: nan, 768: nan, 769: nan, 770: nan, 771: nan, 772: nan, 773: nan, 774: nan, 775: nan, 776: nan, 777: nan, 778: nan, 779: 3.125, 780: nan, 781: nan, 782: nan, 783: nan, 784: nan, 785: 2.0, 786: nan, 787: nan, 788: nan, 789: nan, 790: nan, 791: nan, 792: nan, 793: nan, 794: nan, 795: nan, 796: nan, 797: nan, 798: nan, 799: nan, 800: nan,
801: 2.0, 802: 2.0, 803: 2.5, 804: 3.625, 805: 2.0, 806: 3.625, 807: 2.0, 808: 2.0, 809: 2.0, 810: nan, 811: 2.75, 812: 2.0, 813: 2.0, 814: nan, 815: 4.0, 816: nan, 817: nan, 818: nan, 819: nan, 820: 4.5, 821: nan, 822: nan, 823: nan, 824: 2.836, 825: nan, 826: nan, 827: 2.0, 828: 2.25, 829: nan, 830: nan, 831: 3.525, 832: 3.21, 833: nan, 834: 2.978, 835: nan, 836:
2.0, 837: 3.687, 838: 2.0, 839: 2.6, 840: nan, 841: 3.042, 842: 2.458, 843: 2.0, 844: nan, 845: 3.432, 846: nan, 847: 2.57, 848: nan, 849: 2.083, 850: nan, 851: nan, 852: nan, 853: nan, 854: 2.0, 855: nan, 856: 4.79, 857: 2.0, 858: 3.091, 859: nan, 860: 4.134, 861: nan, 862: 2.761, 863: nan, 864: 2.489, 865: nan, 866: 3.375, 867: nan, 868: nan, 869: 3.749, 870: nan, 871: 2.875, 872: nan, 873: 5.735, 874: 4.66, 875: 2.0, 876: 2.0, 877: nan, 878: 2.125, 879: nan, 880: 2.875, 881: 2.0, 882: nan, 883: 2.0, 884: 4.309, 885: nan, 886: 2.0, 887: nan, 888: nan, 889: 4.954, 890: 2.0, 891: 2.0, 892: 2.9, 893: 2.0, 894: nan, 895: 2.0, 896: 2.0, 897: nan, 898: nan, 899: nan, 900: 3.485, 901: nan, 902: nan, 903: nan, 904: 3.323, 905: nan,
906: nan, 907: nan, 908: 2.0, 909: nan, 910: 3.873, 911: 5.236, 912: 4.542, 913: 3.765, 914: 2.0, 915: nan, 916: nan, 917: 2.0, 918: nan, 919: 3.0, 920: 4.788, 921: nan, 922: 3.307, 923: 2.0, 924: 3.688, 925: nan, 926: nan, 927: 3.56, 928: 4.67, 929: nan, 930: 3.764, 931: nan, 932: 2.0, 933: 2.0, 934: 2.0, 935: 3.077, 936: nan, 937: 3.635, 938: 2.549, 939: nan, 940: nan, 941: 4.757, 942: 2.75, 943: 2.625, 944: 2.0, 945: 4.144, 946: 2.0, 947: 2.0, 948: 3.125, 949: 5.04, 950: nan, 951: 2.0, 952: nan, 953: nan, 954: 3.375, 955: 3.62, 956: nan, 957:
2.0, 958: 3.286, 959: 2.0, 960: 3.5, 961: 2.125, 962: nan, 963: nan, 964: 2.999, 965: 3.625, 966: 4.18, 967: nan, 968: 4.104, 969: 2.0, 970: 3.462, 971: nan, 972: 2.0, 973: nan, 974: nan, 975: nan, 976: 2.0, 977: nan, 978: nan, 979: nan, 980: 3.407, 981: nan, 982: 2.0, 983: nan, 984: 2.0, 985: nan, 986: 3.25, 987: 3.125, 988: 3.0, 989: nan, 990: nan, 991: 2.0, 992:
nan, 993: 3.36, 994: 2.55, 995: nan, 996: 5.658, 997: nan, 998: 3.562, 999: 2.0, 1000: nan, 1001: nan, 1002: 2.0, 1003: nan, 1004: nan, 1005: nan, 1006: 3.608, 1007: nan, 1008: nan, 1009: nan, 1010: 4.0, 1011: 2.625, 1012: 2.0, 1013: 2.751, 1014: nan, 1015: nan, 1016: 2.5, 1017: nan, 1018: nan, 1019: 6.288, 1020: 2.0, 1021: nan, 1022: 2.515, 1023: nan, 1024: 2.0, 1025: 4.055, 1026: 2.0, 1027: 4.0, 1028: 2.588, 1029: 2.0, 1030: 2.0, 1031: 2.0, 1032: nan, 1033: 4.0, 1034: 2.0, 1035: 2.0, 1036: 2.57, 1037: 2.0, 1038: 2.308, 1039: nan, 1040: nan, 1041: 3.834, 1042: nan, 1043: 2.62, 1044: 2.0, 1045: 2.0, 1046: 2.0, 1047: nan, 1048: 2.446, 1049: 3.573, 1050: nan, 1051: nan, 1052: nan, 1053: nan, 1054: nan, 1055: 2.0, 1056: 2.0, 1057: 3.3, 1058: nan, 1059: 2.764, 1060: nan, 1061: 3.476, 1062: 2.0, 1063: nan, 1064: nan, 1065: nan, 1066: 2.0, 1067: 2.0, 1068: nan, 1069: nan, 1070: 2.0, 1071: nan, 1072: nan, 1073: nan, 1074: nan, 1075: 2.0, 1076: 2.0, 1077: 2.0, 1078: 2.0, 1079: 2.0, 1080: nan, 1081: 2.0, 1082: nan, 1083: 2.0, 1084: 2.0, 1085: 2.0, 1086: 2.706, 1087: 2.0, 1088: 2.997, 1089: nan, 1090: 2.0, 1091: nan, 1092: nan, 1093: nan, 1094: 2.0, 1095: nan, 1096: nan, 1097: 4.0, 1098: nan, 1099: 3.875, 1100: nan, 1101: 3.375, 1102: nan, 1103: nan, 1104: nan, 1105: nan, 1106: nan, 1107: 3.125, 1108: nan, 1109: nan, 1110: nan, 1111: 2.625, 1112: nan, 1113: nan, 1114: nan, 1115: nan, 1116: nan, 1117: nan, 1118: nan, 1119: nan, 1120: 2.0, 1121: nan, 1122: nan, 1123: 2.0, 1124: nan, 1125: 2.0, 1126: 2.25, 1127: nan, 1128: nan, 1129: 2.0, 1130: nan, 1131: nan, 1132: 0.25, 1133: nan, 1134: nan, 1135: 2.125, 1136: nan, 1137: nan, 1138: 2.0, 1139: nan, 1140: nan, 1141: nan, 1142: nan, 1143: nan, 1144: nan, 1145: 7.0, 1146: nan, 1147: nan, 1148: nan, 1149: nan, 1150: 3.0, 1151: nan, 1152: nan, 1153: nan, 1154: nan, 1155: 5.0, 1156: nan, 1157: nan, 1158: 4.0, 1159: nan, 1160: nan, 1161: nan, 1162: nan, 1163: nan, 1164: nan, 1165: nan, 1166: nan, 1167: nan, 1168: nan, 1169: nan, 1170: 3.5, 1171: nan, 1172: nan, 1173: nan, 1174: nan, 1175: nan, 1176: nan, 1177: 3.725, 1178: 3.625, 1179: nan, 1180: nan, 1181: nan, 1182: 2.0, 1183: 2.0, 1184: 2.0, 1185: 2.0, 1186: nan, 1187: 2.0, 1188: nan,
1189: nan, 1190: nan, 1191: nan, 1192: nan, 1193: 3.25, 1194: nan, 1195: nan, 1196: 3.0, 1197: nan, 1198: 3.0, 1199: nan, 1200: nan, 1201: 3.0, 1202: nan, 1203: nan, 1204: nan, 1205: nan, 1206: nan, 1207: nan, 1208: nan, 1209: 3.125, 1210: nan, 1211: 4.5, 1212: nan, 1213: nan, 1214: nan, 1215: nan, 1216: nan, 1217: nan, 1218: nan, 1219: nan, 1220: nan, 1221: nan, 1222: nan, 1223: nan, 1224: nan, 1225: nan, 1226: nan, 1227: nan, 1228: 4.0, 1229: nan, 1230: nan, 1231: nan, 1232: nan, 1233: nan, 1234: nan, 1235: 3.4, 1236: nan, 1237: nan, 1238: nan, 1239: nan, 1240: nan, 1241: nan, 1242: nan, 1243: nan, 1244: nan, 1245: nan, 1246: nan, 1247: nan, 1248: nan, 1249: nan, 1250: nan, 1251: nan, 1252: nan, 1253: nan, 1254: nan, 1255: nan, 1256: nan, 1257: nan, 1258: nan, 1259: nan, 1260: nan, 1261: nan, 1262: nan, 1263: nan, 1264: nan, 1265: nan, 1266: nan, 1267: nan, 1268: nan, 1269: nan, 1270: nan, 1271: nan, 1272: 2.0, 1273: 2.125, 1274: nan, 1275: nan, 1276: nan, 1277: nan, 1278: nan, 1279: nan, 1280: nan, 1281: nan, 1282: nan, 1283: nan, 1284: nan, 1285: nan, 1286: nan, 1287: nan, 1288: nan, 1289: nan, 1290: nan, 1291: nan, 1292: nan, 1293: nan, 1294: nan, 1295: nan, 1296: 6.0, 1297: nan, 1298: nan, 1299: nan, 1300: nan, 1301: nan, 1302: nan, 1303: nan, 1304: nan, 1305: nan, 1306: nan, 1307: nan, 1308: nan, 1309: nan, 1310: nan, 1311: nan, 1312: nan, 1313: nan, 1314: nan, 1315: nan, 1316: nan, 1317: nan, 1318: nan, 1319: 2.0, 1320: nan, 1321: nan, 1322: 2.0, 1323: nan, 1324: nan, 1325: nan, 1326: nan, 1327: nan, 1328: nan, 1329: nan, 1330: 2.0, 1331: nan, 1332: nan, 1333: nan, 1334: nan, 1335: nan, 1336: nan, 1337: nan, 1338: nan, 1339: nan, 1340: nan, 1341: nan, 1342: nan, 1343: nan, 1344: nan, 1345: nan, 1346: 8.75, 1347: nan, 1348: nan, 1349: 8.99, 1350: nan, 1351: nan, 1352: nan, 1353: nan, 1354: nan, 1355: nan}, 'StepRate2': {0: nan, 1: nan, 2: nan, 3: nan, 4: '', 5: nan, 6: nan, 7: nan, 8: nan, 9: nan, 10: nan, 11: nan, 12: nan, 13: nan, 14: nan, 15: nan, 16: nan, 17: nan, 18: nan, 19: nan, 20: nan, 21: nan, 22: nan, 23: nan, 24: nan, 25: nan, 26: nan, 27: nan, 28: nan, 29: nan, 30: nan, 31: nan, 32: nan, 33: nan, 34: nan, 35: nan, 36: nan, 37: nan, 38: nan, 39: nan,
40: nan, 41: nan, 42: nan, 43: 7.0, 44: nan, 45: nan, 46: nan, 47: nan, 48: nan, 49: nan, 50: nan, 51: nan, 52: nan, 53: nan, 54: nan, 55: nan, 56: nan, 57: nan, 58: nan, 59: nan, 60:
nan, 61: nan, 62: nan, 63: nan, 64: nan, 65: nan, 66: nan, 67: nan, 68: nan, 69: nan, 70: nan, 71: nan, 72: nan, 73: nan, 74: nan, 75: nan, 76: nan, 77: nan, 78: nan, 79: nan, 80: nan, 81: nan, 82: nan, 83: nan, 84: 4.75, 85: nan, 86: nan, 87: nan, 88: nan, 89: nan, 90: nan, 91: nan, 92: 4.75, 93: 4.0, 94: nan, 95: nan, 96: nan, 97: nan, 98: nan, 99: nan, 100: nan,
101: nan, 102: 6.3459, 103: nan, 104: nan, 105: 4.0, 106: nan, 107: nan, 108: nan, 109: nan, 110: nan, 111: nan, 112: nan, 113: nan, 114: nan, 115: nan, 116: nan, 117: nan, 118: 4.0, 119: nan, 120: '', 121: nan, 122: nan, 123: 4.0, 124: 4.0, 125: 4.0, 126: nan, 127: nan, 128: nan, 129: nan, 130: '', 131: 9.57, 132: nan, 133: nan, 134: 5.5, 135: 4.5, 136: 3.0, 137: nan, 138: nan, 139: nan, 140: nan, 141: 5.25, 142: 3.125, 143: 5.0, 144: 4.5, 145: 5.25, 146: nan, 147: '', 148: '', 149: 9.887, 150: nan, 151: 9.6, 152: nan, 153: 11.99, 154: 11.74, 155: 5.5, 156: nan, 157: nan, 158: nan, 159: 3.0, 160: nan, 161: 8.34, 162: nan, 163: nan, 164: nan, 165: 9.39, 166: 10.0, 167: 3.0, 168: nan, 169: nan, 170: nan, 171: nan, 172: 9.99, 173: nan, 174: nan, 175: nan, 176: 8.385, 177: nan, 178: nan, 179: 3.0, 180: nan, 181: nan, 182: nan, 183: nan, 184: nan, 185: nan, 186: '', 187: nan, 188: 7.48, 189: nan, 190: nan, 191: nan, 192: nan, 193: nan, 194: nan, 195: '', 196: 6.0, 197: nan, 198: nan, 199: 9.54, 200: nan, 201: 4.0, 202: nan, 203: nan, 204: nan, 205: nan, 206: nan, 207: nan, 208: nan, 209: nan, 210: nan, 211: 3.0, 212: nan, 213: nan, 214: 5.0, 215: nan, 216: 9.65, 217: 3.0, 218: nan, 219: nan, 220: nan, 221: nan, 222: nan, 223: 7.45, 224: 7.98, 225: 6.8, 226: nan, 227: nan, 228: nan, 229: '', 230: '', 231: 3.0, 232: 8.385, 233: nan, 234: nan, 235: nan, 236: '', 237: nan, 238: nan, 239: nan, 240: nan, 241: nan, 242: nan, 243: nan, 244: nan, 245: nan, 246: nan, 247: 5.5, 248: nan, 249: nan, 250: nan, 251: nan, 252: nan, 253: 4.0, 254: nan, 255: nan, 256: nan, 257: nan, 258: nan, 259: nan, 260: nan, 261: 4.0, 262: nan, 263: 5.125, 264: 9.033, 265: nan, 266: nan, 267: nan, 268: nan, 269: 3.0, 270: nan, 271: nan, 272: 5.75, 273: nan, 274: 5.25, 275: nan, 276: nan, 277: 3.0, 278: 3.0, 279: 3.0, 280: 4.0, 281: nan, 282: 3.0, 283: 3.0, 284: 4.0, 285: nan, 286: nan, 287: 4.0, 288: 3.0, 289: nan, 290: nan, 291: nan, 292: nan, 293: 4.375, 294: nan, 295: 3.0, 296: 3.0, 297: 3.0, 298: nan, 299: 3.0, 300: 4.25, 301: nan, 302: 3.0, 303: nan, 304: 3.375, 305: nan, 306: 4.0, 307: nan, 308: nan, 309: nan, 310: nan, 311: nan, 312: nan, 313: 4.5, 314: nan, 315: nan, 316: nan, 317: nan, 318: 4.25, 319: nan, 320: 3.0, 321: nan, 322: nan, 323: nan, 324: nan, 325: nan, 326: nan, 327: nan, 328: nan, 329: 4.125, 330: nan, 331: nan, 332: nan, 333: nan, 334: nan, 335: nan, 336: nan,
337: nan, 338: nan, 339: nan, 340: nan, 341: 4.0, 342: nan, 343: nan, 344: nan, 345: nan, 346: nan, 347: nan, 348: nan, 349: nan, 350: 3.0, 351: nan, 352: nan, 353: nan, 354: 3.625, 355: nan, 356: nan, 357: nan, 358: 3.375, 359: 3.0, 360: 3.0, 361: nan, 362: 3.0, 363: nan, 364: nan, 365: 3.0, 366: nan, 367: nan, 368: nan, 369: nan, 370: 3.75, 371: nan, 372: nan, 373: nan, 374: nan, 375: nan, 376: nan, 377: nan, 378: 3.0, 379: 4.75, 380: nan, 381: nan, 382: 3.625, 383: nan, 384: 4.625, 385: nan, 386: nan, 387: nan, 388: nan, 389: 3.625, 390: nan,
391: nan, 392: nan, 393: nan, 394: 4.5, 395: 4.25, 396: nan, 397: 3.625, 398: nan, 399: nan, 400: nan, 401: nan, 402: nan, 403: nan, 404: nan, 405: 3.0, 406: nan, 407: nan, 408: nan, 409: nan, 410: 3.0, 411: nan, 412: nan, 413: nan, 414: nan, 415: 3.5, 416: nan, 417: 3.5, 418: nan, 419: nan, 420: 3.5, 421: nan, 422: 3.0, 423: nan, 424: nan, 425: nan, 426: nan, 427:
nan, 428: nan, 429: nan, 430: nan, 431: 8.5, 432: nan, 433: '', 434: nan, 435: nan, 436: 5.0, 437: 5.24, 438: nan, 439: nan, 440: nan, 441: nan, 442: nan, 443: 7.999, 444: nan, 445: nan, 446: 6.625, 447: nan, 448: nan, 449: 4.0, 450: nan, 451: 3.0, 452: nan, 453: nan, 454: 3.75, 455: 3.5, 456: nan, 457: nan, 458: 3.0, 459: nan, 460: nan, 461: 3.0, 462: nan, 463: 3.0, 464: 3.0, 465: nan, 466: nan, 467: nan, 468: 3.0, 469: 3.0, 470: nan, 471: nan, 472: 3.375, 473: 3.0, 474: 3.0, 475: 3.75, 476: nan, 477: 3.125, 478: 2.5, 479: 3.0, 480: nan, 481: nan, 482: nan, 483: 3.0, 484: nan, 485: nan, 486: nan, 487: nan, 488: nan, 489: nan, 490: nan, 491: 5.0, 492: nan, 493: nan, 494: nan, 495: nan, 496: 4.0, 497: nan, 498: 3.0, 499: nan, 500: nan, 501: nan, 502: nan, 503: nan, 504: '', 505: nan, 506: 3.5, 507: nan, 508: nan, 509: 4.125, 510: nan, 511: nan, 512: nan, 513: nan, 514: nan, 515: 3.0, 516: nan, 517: 7.6, 518: nan, 519: nan, 520: 3.0, 521: nan, 522: nan, 523: nan, 524: nan, 525: 3.0, 526: 3.0, 527: nan, 528: nan, 529: nan, 530: nan, 531: nan, 532: nan, 533: nan, 534: nan, 535: 3.0, 536: nan, 537: 3.0, 538: nan, 539: 3.0, 540: nan, 541: 4.0, 542: nan, 543: nan, 544: 3.0, 545: nan, 546: nan, 547: 3.0, 548: 4.0, 549: 3.0, 550: nan, 551: 3.0, 552: 3.75, 553: nan, 554: nan, 555: nan, 556: nan, 557: nan, 558: 3.0, 559: 3.0, 560: nan, 561: nan, 562: 3.0, 563: nan, 564: nan, 565: 2.875, 566: 3.0, 567: 3.0, 568: nan, 569: 2.5, 570: 3.0, 571: 3.0, 572: nan, 573: nan, 574: 3.0, 575: 3.0, 576: nan, 577: 3.875, 578: nan, 579: 3.0, 580: nan, 581: 3.875, 582: 3.0, 583: 3.25, 584: nan, 585: nan, 586: nan, 587: nan, 588: 2.0, 589: nan, 590: nan, 591: 2.625, 592: 3.0, 593: 3.0, 594: nan, 595: 4.0, 596: nan, 597: nan, 598: nan, 599: nan, 600: 6.375, 601: nan, 602: nan, 603: nan, 604: 4.0, 605: 3.0, 606: 3.0, 607: 3.905, 608: 5.219, 609: nan, 610: 3.0, 611: 4.042, 612: nan, 613: 3.003, 614: 3.0, 615: 3.0, 616: 3.0, 617: 4.282, 618: nan, 619: 5.25, 620: nan, 621: nan, 622: nan, 623: nan, 624: 6.859, 625: nan, 626: 3.551, 627: nan, 628: 4.0, 629: nan, 630: nan, 631: 3.0, 632: 2.114, 633: 4.456, 634: 2.0, 635: nan, 636: 6.06, 637: 6.671, 638: 3.63, 639: nan, 640: nan, 641: 6.144, 642: 2.511, 643: 2.573, 644: nan, 645: nan, 646: 5.09, 647: nan, 648: 3.03, 649: 3.92, 650: 2.922, 651: 4.145, 652: nan, 653: nan, 654: 6.166, 655: nan, 656: 3.5, 657: nan, 658: 3.0, 659: nan, 660: 6.25, 661: nan, 662: nan, 663: nan, 664: nan, 665: 3.0, 666: nan, 667: 3.0, 668: 4.07, 669: 7.04, 670: 5.672, 671: 3.0, 672: 3.0, 673: nan, 674: 3.43, 675: nan, 676: 3.0, 677: nan, 678: 6.226, 679: nan, 680: 3.595, 681: nan, 682: 3.0, 683: nan, 684: nan, 685: nan, 686: nan, 687: 6.27, 688: nan, 689: 4.25, 690: 6.25, 691: 3.0, 692: 6.0, 693: nan, 694: 4.532, 695: 4.26, 696: 2.678, 697: 5.0, 698: 4.6, 699: 4.63, 700: 7.09, 701: nan, 702: nan, 703: 3.0, 704: nan, 705: nan, 706: nan, 707: 6.68, 708: 4.0, 709: 3.43, 710: nan, 711: nan, 712: nan, 713: 3.0, 714: 5.13, 715: 3.0, 716: 3.0, 717: 4.0, 718: 4.04, 719: nan, 720: 3.59, 721: nan, 722: 4.125, 723: 5.0, 724: nan, 725: 4.625, 726: nan, 727: 4.12, 728: 5.0, 729: 3.0, 730: 4.01, 731: 4.0, 732: 3.625, 733: nan, 734: 2.193, 735: 3.0, 736: nan, 737: nan, 738: nan, 739: nan, 740: nan, 741: nan, 742: 3.0, 743: nan, 744: 3.25, 745: 3.0, 746: 3.23, 747: 3.0, 748: 4.375, 749: 4.0, 750: 3.125, 751: nan, 752: 3.72, 753: nan, 754: nan, 755: nan, 756: nan, 757: nan, 758: nan, 759: 7.0, 760: 4.88, 761: 3.87, 762: 4.847, 763: 3.0, 764: 3.441, 765: 3.0, 766: nan, 767: nan, 768: nan, 769: nan, 770: nan, 771: nan, 772: nan, 773: nan, 774: nan, 775: nan, 776: nan, 777: nan, 778: nan, 779: 4.125, 780: nan, 781: nan, 782: nan, 783: nan, 784: nan, 785: 3.0, 786: nan, 787: nan, 788: nan, 789: nan, 790: nan, 791: nan, 792: nan, 793: nan, 794: nan, 795: nan, 796: nan, 797: nan, 798: nan, 799: nan, 800: nan, 801: 3.0, 802: 3.0, 803: 3.5, 804: 4.625, 805: 3.0, 806: 4.625, 807: 3.0, 808: 3.0, 809: 3.0, 810: nan, 811: 3.75, 812: 3.0, 813: 3.0, 814: nan, 815: 4.0, 816: nan, 817: nan, 818: nan, 819: nan, 820: 5.5, 821: nan, 822: nan, 823: nan, 824: 3.75, 825: nan, 826: nan, 827: 3.0, 828: 3.25, 829: nan, 830: nan, 831: 3.86, 832: 4.0, 833: nan, 834: 3.978, 835: nan, 836: 3.0, 837: 4.687, 838: 3.0, 839: 3.6, 840: nan, 841: 4.042, 842: 3.43, 843: 3.0, 844: nan, 845: 4.432, 846: nan, 847: 3.57, 848: nan, 849: 3.083, 850: nan, 851: nan, 852: nan, 853: nan, 854: 3.0, 855: nan,
856: 5.794, 857: 3.0, 858: 4.091, 859: nan, 860: 5.134, 861: nan, 862: 3.5, 863: nan, 864: 3.489, 865: nan, 866: 3.625, 867: nan, 868: nan, 869: 3.75, 870: nan, 871: 3.875, 872: nan, 873: 6.735, 874: 5.66, 875: 3.0, 876: 3.0, 877: nan, 878: 4.01, 879: nan, 880: 3.875, 881: 3.0, 882: nan, 883: 3.0, 884: 5.309, 885: nan, 886: 3.0, 887: nan, 888: nan, 889: 5.25, 890: 3.0, 891: 3.0, 892: 3.875, 893: 3.0, 894: nan, 895: 3.0, 896: 3.0, 897: nan, 898: nan, 899: nan, 900: 4.485, 901: nan, 902: nan, 903: nan, 904: 3.504, 905: nan, 906: nan, 907: nan, 908: 3.0, 909: nan, 910: 4.25, 911: 6.236, 912: 5.542, 913: 4.0, 914: 3.0, 915: nan, 916: nan, 917: 3.0, 918: nan, 919: 3.75, 920: 5.788, 921: nan, 922: 4.307, 923: 3.0, 924: 4.688, 925: nan, 926: nan, 927: 3.88, 928: 5.67, 929: nan, 930: 4.764, 931: nan, 932: 3.0, 933: 3.0, 934: 3.0, 935: 4.077, 936: nan, 937: 4.635, 938: 3.549, 939: nan, 940: nan, 941: 5.757, 942: 3.5, 943: 3.625, 944: 3.0, 945: 5.144, 946: 3.0, 947: 2.797, 948: 3.64, 949: 6.0, 950: nan, 951: 3.0, 952: nan, 953: nan, 954: 3.41, 955: 4.0, 956: nan, 957: 3.0, 958: 3.5, 959: 2.613, 960: 3.875, 961: 3.125, 962: nan, 963: nan, 964: 3.41, 965: 3.64, 966: 5.18, 967: nan, 968: 4.75, 969: 3.0, 970: 4.105, 971: nan, 972: 3.0, 973: nan, 974: nan, 975: nan, 976: 3.0, 977: nan, 978: nan, 979: nan, 980: 4.407, 981: nan, 982: 3.0, 983: nan, 984: 3.0, 985: nan, 986: 4.25, 987: 4.0, 988: 3.43, 989: nan, 990: nan, 991: 3.0, 992: nan, 993: 4.36, 994: 3.55, 995: nan, 996: 6.46, 997: nan, 998: 4.562, 999: 3.0, 1000: nan, 1001: nan, 1002: 3.0, 1003: nan, 1004: nan, 1005: nan, 1006: 4.608, 1007: nan, 1008: nan, 1009: nan, 1010: 4.51, 1011: 3.625, 1012: 3.0, 1013: 3.5, 1014: nan, 1015: nan, 1016: 3.5, 1017: nan, 1018: nan, 1019: 7.288, 1020: 3.0, 1021: nan, 1022: 3.515, 1023: nan, 1024: 3.0, 1025: 4.125, 1026: 3.0, 1027: 4.08, 1028: 3.375, 1029: 3.0, 1030: 3.0, 1031: 3.0, 1032: nan, 1033: 4.25, 1034: 3.0, 1035: 3.0, 1036: 3.57, 1037: 3.0, 1038: 3.308, 1039: nan, 1040: nan, 1041: 4.125, 1042: nan, 1043: 3.5, 1044: 3.0, 1045: 2.969, 1046: 3.0, 1047: nan, 1048: 3.446, 1049: 4.5, 1050: nan, 1051: nan, 1052: nan, 1053: nan, 1054: nan, 1055: 3.0, 1056: 3.0, 1057: 3.306, 1058: nan, 1059: 3.764, 1060: nan, 1061: 3.8, 1062: 3.0, 1063: nan, 1064: nan, 1065: nan, 1066: 3.0, 1067: 3.0, 1068: nan, 1069: nan, 1070: 3.0, 1071: nan, 1072: nan, 1073: nan, 1074: nan, 1075: 3.0, 1076: 3.0, 1077: 3.0, 1078: 3.0, 1079: 3.0, 1080: nan, 1081: 2.491, 1082: nan, 1083: 3.0, 1084: 3.0, 1085: 3.0, 1086: 3.706, 1087: 3.0, 1088: 3.997, 1089: nan, 1090: 2.37, 1091: nan, 1092: nan, 1093: nan, 1094: 3.0, 1095: nan, 1096: nan, 1097: 4.0, 1098: nan, 1099: 4.5, 1100: nan, 1101: 4.25, 1102: nan, 1103: nan, 1104: nan, 1105: nan, 1106: nan, 1107: 4.125, 1108: nan, 1109: nan, 1110: nan, 1111: 3.625, 1112: nan, 1113: nan, 1114: nan, 1115: nan, 1116: nan, 1117: nan, 1118: nan, 1119: nan, 1120: 3.0, 1121: nan, 1122: nan, 1123: 3.0, 1124: nan, 1125: 3.0, 1126: 3.25, 1127: nan, 1128: nan, 1129: 2.0, 1130: nan, 1131: nan, 1132: 1.25, 1133: nan, 1134: nan, 1135: 3.5, 1136: nan, 1137: nan, 1138: 3.0, 1139: nan, 1140: nan, 1141: nan, 1142: nan, 1143: nan, 1144: nan, 1145: 11.83, 1146: nan, 1147: nan, 1148: nan, 1149: nan, 



from Iterating through specific columns and rows in pandas dataframe to perform a check