All posts by stackoverflow

Importing Excel data to multi dimensional array in C#

I am trying to import data from an excel sheet from certain cells for example Column A and B into a multidimensional array.

        Excel.Application xlApp = new Excel.Application();
        Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\\Users\\a_hebiba\\Desktop\\Lol1.xlsx");
        Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
        Array Cranelocations;
        Excel.Range xlRange = xlWorksheet.get_Range("A", "B".ToString());



        Cranelocations = (Array)xlRange.Cells.Value;
        Console.WriteLine(Cranelocations);
        Console.ReadLine();

then i am trying to take these data from the array to apply a certain equation on it but i don’t know how to read the data from the array anymore.

for (int m = 0; m < Weights.Length; m++)
        {
            int offset = m * Cranelocations.GetLength(0);

            for (int i = 0; i < Cranelocations.GetLength(0); i++)
            {
                for (int j = 0; j < Picklocation.GetLength(0); j++)
                {
                    double x = Cranelocations[i,0]- Picklocation[j, 0];
                    double y = Cranelocations[i, 1] - Picklocation[j, 1];

                    result1[i + offset, j] = Weights[m] * (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)));
                }
            }
        }

read more

How to use image() function to plot the data in R

I have a clinical dataset and I would like to plot it using image() function to see if I can spot out the different groups within my data.

The structure of this data is a List of 2: 56 samples and 5000 gene expressions.

When I use image(lung), all I see a just a plot of orange color and I do not see pattern or any group standing out to me.

Basically, there are four types of clinical conditions in the dataset: Colon cancer (13 samples), smallcell (6 samples), etc.

read more

Want to have multiple geoJson Overlay on leaflet map

based on folium Timestamped GeoJSON macro i want to have 2 geoJSON Layer on one map to have it selectable via the layerControl. But actually it creates two time sliders and it is not selectable via the layerControl.

On the following way both layers were added to the map:

L.timeDimension.layer.geoJson(geoJsonLayer,
                {updateTimeDimension: false,
                }).addTo(base_map)

The existend folium code is now taken layer_name and the layer object of all children from the parent map (base_map). And to have the geoJSON as an overlay I guess I need to define a layer_name. But this property is not available?!
Any ideas or solutions?

read more

Generic FactoryMethod Instance provider with Lightinject

In my previous project, I used Ninject to achieve autogeneration of actions. I had a generic ActionsFactory interface, which looked like this:

public interface IActionsFactory
{
    TAction GetAction<TAction>();
}

Ninject was configured to bind this interface to a factory:

kernel.Bind<IActionsFactory>().ToFactory(() => new GenericFactoryMethodInstanceProvider());

public class GenericFactoryMethodInstanceProvider : StandardInstanceProvider
{
    protected override string GetName(MethodInfo methodInfo, object[] arguments)
    {
        return null;
    }
}

With this, I could reference in my controllers only IActionFactory, without the need to reference all of the actions, like this:

public class SomeController : ApiController
{
    private readonly IActionsFactory 

    public SomeController(IActionsFactory actionsFactory)
    {
        this.actionsFactory = actionsFactory;
    }

    [HttpGet]
    public async Task<Foo> GetFoo()
    {
        retutn await actionsFactory.GetAction<IFooAction>().GetSomeFoo();
    }
}

read more

Is there a way to call my function based on the amount of time the user inputed

I am writing a program for a quote generator and I need some help getting my quote to generator a set number of times depending on what the user input.

I’ve tried to iterate and pus the result into an array but it only pushes the same result for e.g 4 times

//Flowers quotes
‘use strict’;

const randomFlowersQuote = () => {

const fragBeginning = ['These are very beautiful ', 'I like looking at ', ' Today We saw some new ', 'There a nice '];
const fragMiddle = ['flower pots', 'hibiscuss trees', 'red roses', 'lily flowers', 'rare flowers'];

const fragEnd = [' i would love to buy one', ' they are very nice', ' they are so breathtaking', ' in the shop'];

//Random generated quotes

const fragBeginningRandom = [Math.floor(Math.random() * fragBeginning.length)];
const fragMiddelRandom = [Math.floor(Math.random() * fragMiddle.length)];
const fragEndRandom = [Math.floor(Math.random() * fragBeginning.length)];
const fullQuote = [fragBeginning[fragBeginningRandom] + fragMiddle[fragMiddelRandom] + fragEnd[fragEndRandom]];

return fullQuote;

read more