问:
In get(object, envir = currentEnv, inherits = TRUE) : restarting interrupted promise evaluation
The issue: Function not able to evaluate arguments properly.
The symptom: When attempting to evaluate the x and y arguments in a ggplot aes() statement, the function returns an error, saying not able to find the object being passed in the argument, and then giving the error:

```<code>In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
</code>```

Here is the code:

```<code>plot_vote_by_state <-
  function(dsrce,
       x_axis_srce,
       y_axis_srce,
       point_labels = NULL,
       point_color_key = NULL,
       data_fit_srce = NULL,
       title_txt = NULL,
       sub_title_txt = NULL,
       x_lbl_txt = NULL,
       y_lbl_txt = NULL,
       caption_txt = NULL) {
basic_plot <- ggplot(
  dsrce,
  aes(
    x_axis_srce,
    y_axis_srce
  )
) + geom_point()
print(basic_plot)
  }
</code>```

Here is a link to the data: https://1drv.ms/u/s!AolqFDwBowVjlMBVELC8qhwXkt8jPQ?e=m63GYO

Here is the command line that I'm using to invoke the function:

```<code>plot_vote_by_state(dsrce = GDP_vs_pcnt_Biden_Vote, x_axis_srce = GDP_per_Capita, y_axis_srce = Vote_share_pcnt)
</code>```

Heres a look at the first row of the dsrce argument from within the debug environment; this shows the column names:

```<code>Browse[2]> dsrce
  State Vote_share_pcnt    GDP   fit Population GDP_per_Capita per_capita_fit EC    Ten_yr_avg_unemp Unemp_fit

1 AL              0.366   908. 0.475    5024279           181.          0.430 TRUMP             7.33     0.513
</code>```

However, when I try to look at one of the aes() arguments while in debug, I get this:

```<code>Browse[2]> x_axis_srce
Error: object 'GDP_per_Capita' not found
In addition: Warning messages:
1: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
2: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
3: restarting interrupted promise evaluation
</code>```

When the GDP_per_Capita column is clearly there in the dsrce.

If I manually run ggplot while in the debug environment by typing the actual argument names into the aes() argument (ie: not using the x_axis_srce and y_axis_srce assigned variables) the plot function works as it should.

But it will not work if I try to use the assigned x_axis_srce and y_axis_srce variables that are passed through to the funtion.

It also blows up if I do a colnames(dsrce) command while in the debug environment:

```<code>Browse[2]> colnames(dsrce)

[1] "State"            "Vote_share_pcnt"  "GDP"              "fit"              "Population"       "GDP_per_Capita"   "per_capita_fit"   "EC"
 [9] "Ten_yr_avg_unemp" "Unemp_fit"
Warning messages:
1: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
2: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
3: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
4: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
5: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
6: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
7: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
8: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
9: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
10: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
</code>```

Help!  What's going on here?

答:
Your current use of the function is using "standard evaluation", so aes(x_axis_srce, y_axis_srce) is wrong: ggplot2 is using non-standard evaluation (NSE), so will look for a column labeled literally "x_axis_srce" in the data, which it won't find. See Programming with ggplot2, specifically the Indirectly referring to variables section.

However, even that reference is a little outdated, as aes_ and aes_string are both soft-deprecated, both deferring to a new strategy: .data$ or {{.}}. See https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html#using-aes-and-vars-in-a-package-function-1.

Try this instead:

plot_vote_by_state <-
  function(dsrce,
           x_axis_srce,
           y_axis_srce,
           point_labels = NULL,
           point_color_key = NULL,
           data_fit_srce = NULL,
           title_txt = NULL,
           sub_title_txt = NULL,
           x_lbl_txt = NULL,
           y_lbl_txt = NULL,
           caption_txt = NULL) {
    basic_plot <- ggplot(
      dsrce,
      aes(
        {{ x_axis_srce }},
        {{ y_axis_srce }}
      )
    ) + geom_point()
    print(basic_plot)
  }
```

Body:
The issue: Function not able to evaluate arguments properly.
The symptom: When attempting to evaluate the x and y arguments in a ggplot aes() statement, the function returns an error, saying not able to find the object being passed in the argument, and then giving the error:

In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation

Here is the code:

plot_vote_by_state <-
  function(dsrce,
       x_axis_srce,
       y_axis_srce,
       point_labels = NULL,
       point_color_key = NULL,
       data_fit_srce = NULL,
       title_txt = NULL,
       sub_title_txt = NULL,
       x_lbl_txt = NULL,
       y_lbl_txt = NULL,
       caption_txt = NULL) {
basic_plot <- ggplot(
  dsrce,
  aes(
    x_axis_srce,
    y_axis_srce
  )
) + geom_point()
print(basic_plot)
  }

Here is a link to the data: https://1drv.ms/u/s!AolqFDwBowVjlMBVELC8qhwXkt8jPQ?e=m63GYO

Here is the command line that I'm using to invoke the function:

plot_vote_by_state(dsrce = GDP_vs_pcnt_Biden_Vote, x_axis_srce = GDP_per_Capita, y_axis_srce = Vote_share_pcnt)

Heres a look at the first row of the dsrce argument from within the debug environment; this shows the column names:

Browse[2]> dsrce
  State Vote_share_pcnt    GDP   fit Population GDP_per_Capita per_capita_fit EC    Ten_yr_avg_unemp Unemp_fit

1 AL              0.366   908. 0.475    5024279           181.          0.430 TRUMP             7.33     0.513

However, when I try to look at one of the aes() arguments while in debug, I get this:

Browse[2]> x_axis_srce
Error: object 'GDP_per_Capita' not found
In addition: Warning messages:
1: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
2: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
3: restarting interrupted promise evaluation

When the GDP_per_Capita column is clearly there in the dsrce.

If I manually run ggplot while in the debug environment by typing the actual argument names into the aes() argument (ie: not using the x_axis_srce and y_axis_srce assigned variables) the plot function works as it should.

But it will not work if I try to use the assigned x_axis_srce and y_axis_srce variables that are passed through to the funtion.

It also blows up if I do a colnames(dsrce) command while in the debug environment:

Browse[2]> colnames(dsrce)

[1] "State"            "Vote_share_pcnt"  "GDP"              "fit"              "Population"       "GDP_per_Capita"   "per_capita_fit"   "EC"
 [9] "Ten_yr_avg_unemp" "Unemp_fit"
Warning messages:
1: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
2: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
3: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
4: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
5: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
6: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
7: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
8: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
9: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation
10: In get(object, envir = currentEnv, inherits = TRUE) :
  restarting interrupted promise evaluation

Help!  What's going on here?


来源: stackexchange

问:
transforming timeslots using Elixir
I have this data, with timeslots, I am trying to convert them to 15 minutes intervals for the same day.

(elixir 1.10.4,
erlang 23.1.4)

```<code>[
  %{
    day: "fri",
    since: ~T[13:30:00],
    till: ~T[14:15:00],
  },
  %{
    day: "fri",
    since: ~T[15:30:00],
    till: ~T[16:30:00],
  },
]
</code>```

I am trying to convert it to this

```<code>[
  %{
    day: "fri",
    since: ~T[13:30:00],
    till: ~T[13:45:00],
  },
  %{
    day: "fri",
    since: ~T[13:45:00],
    till: ~T[14:00:00],
  },
  %{
    day: "fri",
    since: ~T[14:00:00],
    till: ~T[14:15:00],
  },
  %{
    day: "fri",
    since: ~T[15:30:00],
    till: ~T[15:45:00],
  },
  %{
    day: "fri",
    since: ~T[15:45:00],
    till: ~T[16:00:00],
  },
  %{
    day: "fri",
    since: ~T[16:00:00],
    till: ~T[16:15:00],
  },
  %{
    day: "fri",
    since: ~T[16:15:00],
    till: ~T[16:30:00],
  }
]
</code>```

any help would be wonderful, I am unaware of how to handle indexes within an enum, So I can attach since and till with a map. thanks

答:
Assuming there is no overlapping input, we can use an infinite stream from since adding by 15 minutes until we hit till.

input = [
  %{day: "fri", since: ~T[13:30:00], till: ~T[14:15:00]},
  %{day: "fri", since: ~T[15:30:00], till: ~T[16:30:00]}
]

Enum.flat_map(input, fn
  %{day: day, since: since, till: till} ->
    since
    |> Stream.iterate(& &1 |> Time.add(15 * 60) |> Time.truncate(:second))
    |> Stream.chunk_every(2, 1)
    |> Stream.map(fn [s, t] -> %{day: day, since: s, till: t} end)
    |> Enum.reduce_while([], fn %{till: t} = e, acc ->
         if(Time.compare(t, till) != :gt,
           do: {:cont, [e|acc]},
           else: {:halt, acc})
    end)
    |> Enum.reverse()
end)
```

ContentLicense: CC BY-SA 4.0

Title: transforming timeslots using Elixir

Body:
I have this data, with timeslots, I am trying to convert them to 15 minutes intervals for the same day.

(elixir 1.10.4,
erlang 23.1.4)

[
  %{
    day: "fri",
    since: ~T[13:30:00],
    till: ~T[14:15:00],
  },
  %{
    day: "fri",
    since: ~T[15:30:00],
    till: ~T[16:30:00],
  },
]

I am trying to convert it to this

[
  %{
    day: "fri",
    since: ~T[13:30:00],
    till: ~T[13:45:00],
  },
  %{
    day: "fri",
    since: ~T[13:45:00],
    till: ~T[14:00:00],
  },
  %{
    day: "fri",
    since: ~T[14:00:00],
    till: ~T[14:15:00],
  },
  %{
    day: "fri",
    since: ~T[15:30:00],
    till: ~T[15:45:00],
  },
  %{
    day: "fri",
    since: ~T[15:45:00],
    till: ~T[16:00:00],
  },
  %{
    day: "fri",
    since: ~T[16:00:00],
    till: ~T[16:15:00],
  },
  %{
    day: "fri",
    since: ~T[16:15:00],
    till: ~T[16:30:00],
  }
]

any help would be wonderful, I am unaware of how to handle indexes within an enum, So I can attach since and till with a map. thanks


问:
How to make a working login functions for my website?
I am just entered this game since last December. Now I finished HTML CSS and a little bit of Java Script yet I got stuck at this stage: I can do basic styling but I don't know how to make it interactive.

So my question is :

how can I make a login function for websites, which can gives visitor an account  (sign up, login, forgot password) that can do basic things like comment , add to basket and favorite a product?

Don't need to be specific, please just highlight which language is involved in which stage.

Thanks ahead.

答:
You can use only html/js to create a website. But, if you need authentication, post comments, a server side is needed.
A js can call easely an API to authenticate (server side) and post comments with XHR. You have to create it. You need to know how Authentication headers works for server side. You need to have a database (sql, file or nosql, it's your choice) to save the users datas and rights.</p>


问:
How do i get specific data from a json data (api) using axios in ReactJS
I want to get a Image with spesific Text in caption from Instagram graph api.For example if caption from image has "yes" word in Instagram then must show in homepage.The problem is i know i cant write if promises in axios or maybe i dont know how to write this rule.thank you for your help.

import React from 'react'
import '../styles/home.css'

import axios from 'axios';

export default class Home extends React.Component {
  state = {
    posts: []
  }

  componentDidMount() {
   axios.get(`https://graph.instagram.com/me/media?fields=id,caption,media_url,permalink,username&access_token=IGQ....`)

   .then(res => {
        const posts = res.data.data;
        this.setState({ posts });

      })

  }

  render() {
    return (

        {
          this.state.posts
            .map(post =>

                {
                this.state.posts
                    .map(post =>

{post.username}

                    )
                }
                {this.state.posts
                    .map(post =>

{post.caption}

                    )
                }

            )
        }

        {
                this.state.posts
                    .map(post =>

                    )
                }

    )
  }
}```

答:
You could try .indexOf and make a if statement that finds the string "yes" if its there it will display that picture if not elif or end.

var caption = "This is some generic sentence that contains the word yes";
var substring = "yes";

console.log(caption.indexOf(substring) !== -1)```


问:
creating custom JSON object by using javascript / node js

let data=
[
  {
    system: {
      id: '4gSSbjCFEorYXqrgDIP2FA',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      shortSlugOption: {
        "en-us":`some value`
      },
      mediaFileAssetLink: {
        "za-op":`file Linl`
      },
      mediaFileAssetGalary: {
        "hi":`file link 2`
      },
      singleMediaImage: {
        "li-sd-op":`file link single`
      },
    }
  },
  {
    system: {
      id: '1aBOO8tu3lUsjtICuIbUM5',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      short: {
        "en-us":`details of shorts`
      },
      shortSlugOption: {
        "hi-In":`options`
      },
      booleanField: {
        "kl":`true`
      }
    }
  },
  {
    system: {
      id: '2pOUGnI1oRD7nsrYs600HA',
      type: 'Entry',
      name: `testing`
    },
    DataDetails: { testingNewValue: {
      "en-uk":`details value`
    } }
  },
  {
    system: {
      id: '66rzYr2BpWL1VTBHdLTdSW',
      type: 'Entry',
      name: `new`
    },
    DataDetails: { oneReference: {
      "ru-re":`values 1`
    }, multiReference: {
      "uk-es":`values 2`
    } }
  },
  {
    system: {
      id: 'cIb5mqEBRWDD6hrNmFmFE',
      type: 'Entry',
      name: `new`
    },
    DataDetails: { testingNewValue: {
      "hi-IN":`jksdsdo`
    } }
  },
  {
    system: {
      id: '7kRzyt4PFrX13gHcw3Z1Ko',
      type: 'Entry',
      name: `testing`
    },
    DataDetails: { testingNewValue: {
      "en-us":`kknksdo`
    } }
  },
  {
    system: {
      id: '2OspeCtNK0sh2cPiuU9jIz',
      type: 'Entry',
      name: `dummy`
    },
    DataDetails: {
      short: {
        "gh-we":`dfvndkssa`
      },
      shortSlugOption: {
        "jk-cv":`sdocjosmdc`
      },
      mediaFileAssetLink: {
        "en-us":`jdsojocis`
      },
      booleanField: {
        "cb-af":`true`
      }
    }
  },
  {
    system: {
      id: '2eAmIIuG4xkLvatkU3RUSy',
      type: 'Entry',
      name: `dummy`
    },
    DataDetails: { dummy: {
      "en-us":`dshcifdvk`
    }, india: {
      "kh-vh-we":`sdci`
    } }
  },
  {
    system: {
      id: '7hbdS3MgfZ73TOtlu1WfXw',
      type: 'Entry',
      name: `dummy`
    },
    DataDetails: { testingNewValue: {
      "ax-lo":`sdcoklsdc`
    }, locationField: {
      "sd-op":`sdcndkdc`
    } }
  }
];

data.map((value)=>{
  var name = value.system.id;
  var details={};

  details[name]={
    title:value.system.id,
    uid:value.system.id,
    url:`/${value.system.name}/${value.system.id}`,
  }

  console.log(details)
})```
</div>
</div>
</p>
<p>I am storing my data in JSON file but by doing some modification in my current object.</p>
<p>data I want to store in JSON is like in this way</p>
```{
  "4gSSbjCFEorYXqrgDIP2FA": {
    "title": "4gSSbjCFEorYXqrgDIP2FA",
    "uid": "4gSSbjCFEorYXqrgDIP2FA",
    "url": "/Author/4gSSbjCFEorYXqrgDIP2FA",
    "shortSlugOption": "some value",
    "mediaFileAssetLink": "file Linl"
  },
  "1aBOO8tu3lUsjtICuIbUM5": {
    "title": "1aBOO8tu3lUsjtICuIbUM5",
    "uid": "1aBOO8tu3lUsjtICuIbUM5",
    "url": "/Author/1aBOO8tu3lUsjtICuIbUM5",
    "short": "details of shorts",
    "shortSlugOption": "options",
    "booleanField": "true"
  }
}
```
<p>so to get entries from the Data object I have created map function to get the value and to fetch the DataDetails object I used Object.entries</p>
```for (const [key, value] of Object.entries(value.DataDetails)) {
  console.log(`${key}: ${value}`);
}
```
<p>so I made some changes in my code to get the desire output the problem is I am getting this</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let data=
[
  {
    system: {
      id: '4gSSbjCFEorYXqrgDIP2FA',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      shortSlugOption: {
        "en-us":`some value`
      },
      mediaFileAssetLink: {
        "za-op":`file Linl`
      },
      mediaFileAssetGalary: {
        "hi":`file link 2`
      },
      singleMediaImage: {
        "li-sd-op":`file link single`
      },
    }
  },
  {
    system: {
      id: '1aBOO8tu3lUsjtICuIbUM5',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      short: {
        "en-us":`details of shorts`
      },
      shortSlugOption: {
        "hi-In":`options`
      },
      booleanField: {
        "kl":`true`
      }
    }
  }
];

data.map((value)=>{
  var name = value.system.id;
  var details={};

for (const [key, values] of Object.entries(value.DataDetails)) {

 details[name]={
    title:value.system.id,
    uid:value.system.id,
    url:`/${value.system.name}/${value.system.id}`,
    key:`${values}`
  }

}
  console.log(details)
})</code>```

I was trying to add ${key} but it's not making me to do so I can't get the DataDetails value as key in my object

is there any possible way I can DataDetails value which are shortSlugOption, mediaFileAssetLink by removing en-us,za-op n all

as my expected value is because the name field are common in this  JSON object so I want to store common name field in One JSON file

```<code>{
  "4gSSbjCFEorYXqrgDIP2FA": {
    "title": "4gSSbjCFEorYXqrgDIP2FA",
    "uid": "4gSSbjCFEorYXqrgDIP2FA",
    "url": "/Author/4gSSbjCFEorYXqrgDIP2FA",
    "shortSlugOption": "some value",
    "mediaFileAssetLink": "file Linl"
  },
  "1aBOO8tu3lUsjtICuIbUM5": {
    "title": "1aBOO8tu3lUsjtICuIbUM5",
    "uid": "1aBOO8tu3lUsjtICuIbUM5",
    "url": "/Author/1aBOO8tu3lUsjtICuIbUM5",
    "short": "details of shorts",
    "shortSlugOption": "options",
    "booleanField": "true"
  }
}

</code>```

答:
Is this what you were looking for. Created the details Object separately and spreaded it in the next step. I took the first and only element coming from the Object.values array

let data=
[
  {
    system: {
      id: '4gSSbjCFEorYXqrgDIP2FA',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      shortSlugOption: {
        "en-us":`some value`
      },
      mediaFileAssetLink: {
        "za-op":`file Linl`
      },
      mediaFileAssetGalary: {
        "hi":`file link 2`
      },
      singleMediaImage: {
        "li-sd-op":`file link single`
      },
    }
  }
];

data.map((value)=>{
  var name = value.system.id;
  var details={};

for (const [key, values] of Object.entries(value.DataDetails)) {

let detailsObj = {}
Object.keys(value.DataDetails).forEach((detail) => {
    detailsObj[detail] = Object.values(value.DataDetails[detail])[0]
})

 details[name]={
    title:value.system.id,
    uid:value.system.id,
    url:`/${value.system.name}/${value.system.id}`,
        ...detailsObj
  }

}
  console.log(details)
})```
</div>
</div>
</p>
<p>To group by the <code>name</code> can use <code>Array.reduce</code>
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let data = [{"system":{"id":"4gSSbjCFEorYXqrgDIP2FA","type":"Entry","name":"Author"},"DataDetails":{"shortSlugOption":{"en-us":"some value"},"mediaFileAssetLink":{"za-op":"file Linl"},"mediaFileAssetGalary":{"hi":"file link 2"},"singleMediaImage":{"li-sd-op":"file link single"}}},{"system":{"id":"1aBOO8tu3lUsjtICuIbUM5","type":"Entry","name":"Author"},"DataDetails":{"short":{"en-us":"details of shorts"},"shortSlugOption":{"hi-In":"options"},"booleanField":{"kl":"true"}}},{"system":{"id":"2pOUGnI1oRD7nsrYs600HA","type":"Entry","name":"testing"},"DataDetails":{"testingNewValue":{"en-uk":"details value"}}},{"system":{"id":"66rzYr2BpWL1VTBHdLTdSW","type":"Entry","name":"new"},"DataDetails":{"oneReference":{"ru-re":"values 1"},"multiReference":{"uk-es":"values 2"}}},{"system":{"id":"cIb5mqEBRWDD6hrNmFmFE","type":"Entry","name":"new"},"DataDetails":{"testingNewValue":{"hi-IN":"jksdsdo"}}},{"system":{"id":"7kRzyt4PFrX13gHcw3Z1Ko","type":"Entry","name":"testing"},"DataDetails":{"testingNewValue":{"en-us":"kknksdo"}}},{"system":{"id":"2OspeCtNK0sh2cPiuU9jIz","type":"Entry","name":"dummy"},"DataDetails":{"short":{"gh-we":"dfvndkssa"},"shortSlugOption":{"jk-cv":"sdocjosmdc"},"mediaFileAssetLink":{"en-us":"jdsojocis"},"booleanField":{"cb-af":"true"}}},{"system":{"id":"2eAmIIuG4xkLvatkU3RUSy","type":"Entry","name":"dummy"},"DataDetails":{"dummy":{"en-us":"dshcifdvk"},"india":{"kh-vh-we":"sdci"}}},{"system":{"id":"7hbdS3MgfZ73TOtlu1WfXw","type":"Entry","name":"dummy"},"DataDetails":{"testingNewValue":{"ax-lo":"sdcoklsdc"},"locationField":{"sd-op":"sdcndkdc"}}}]

let res = data.reduce((acc,curr) => {
    if(!acc[curr.system.name]){
    acc[curr.system.name] = {}
  }

  let detailsObj = {}
Object.keys(curr.DataDetails).forEach((detail) => {
    detailsObj[detail] = Object.values(curr.DataDetails[detail])[0]
})

  acc[curr.system.name][curr.system.id] = {
    title:curr.system.id,
    uid:curr.system.id,
        url:`/${curr.system.name}/${curr.system.id}`,
    ...detailsObj
  }
  return acc;
},{})

console.log(res)</code>```

The result of a specific name can be accessed as res['Author'] for example

Body:
let data=
[
  {
    system: {
      id: '4gSSbjCFEorYXqrgDIP2FA',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      shortSlugOption: {
        "en-us":`some value`
      },
      mediaFileAssetLink: {
        "za-op":`file Linl`
      },
      mediaFileAssetGalary: {
        "hi":`file link 2`
      },
      singleMediaImage: {
        "li-sd-op":`file link single`
      },
    }
  },
  {
    system: {
      id: '1aBOO8tu3lUsjtICuIbUM5',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      short: {
        "en-us":`details of shorts`
      },
      shortSlugOption: {
        "hi-In":`options`
      },
      booleanField: {
        "kl":`true`
      }
    }
  },
  {
    system: {
      id: '2pOUGnI1oRD7nsrYs600HA',
      type: 'Entry',
      name: `testing`
    },
    DataDetails: { testingNewValue: {
      "en-uk":`details value`
    } }
  },
  {
    system: {
      id: '66rzYr2BpWL1VTBHdLTdSW',
      type: 'Entry',
      name: `new`
    },
    DataDetails: { oneReference: {
      "ru-re":`values 1`
    }, multiReference: {
      "uk-es":`values 2`
    } }
  },
  {
    system: {
      id: 'cIb5mqEBRWDD6hrNmFmFE',
      type: 'Entry',
      name: `new`
    },
    DataDetails: { testingNewValue: {
      "hi-IN":`jksdsdo`
    } }
  },
  {
    system: {
      id: '7kRzyt4PFrX13gHcw3Z1Ko',
      type: 'Entry',
      name: `testing`
    },
    DataDetails: { testingNewValue: {
      "en-us":`kknksdo`
    } }
  },
  {
    system: {
      id: '2OspeCtNK0sh2cPiuU9jIz',
      type: 'Entry',
      name: `dummy`
    },
    DataDetails: {
      short: {
        "gh-we":`dfvndkssa`
      },
      shortSlugOption: {
        "jk-cv":`sdocjosmdc`
      },
      mediaFileAssetLink: {
        "en-us":`jdsojocis`
      },
      booleanField: {
        "cb-af":`true`
      }
    }
  },
  {
    system: {
      id: '2eAmIIuG4xkLvatkU3RUSy',
      type: 'Entry',
      name: `dummy`
    },
    DataDetails: { dummy: {
      "en-us":`dshcifdvk`
    }, india: {
      "kh-vh-we":`sdci`
    } }
  },
  {
    system: {
      id: '7hbdS3MgfZ73TOtlu1WfXw',
      type: 'Entry',
      name: `dummy`
    },
    DataDetails: { testingNewValue: {
      "ax-lo":`sdcoklsdc`
    }, locationField: {
      "sd-op":`sdcndkdc`
    } }
  }
];

data.map((value)=>{
  var name = value.system.id;
  var details={};

  details[name]={
    title:value.system.id,
    uid:value.system.id,
    url:`/${value.system.name}/${value.system.id}`,
  }

  console.log(details)
})

I am storing my data in JSON file but by doing some modification in my current object.

data I want to store in JSON is like in this way

{
  "4gSSbjCFEorYXqrgDIP2FA": {
    "title": "4gSSbjCFEorYXqrgDIP2FA",
    "uid": "4gSSbjCFEorYXqrgDIP2FA",
    "url": "/Author/4gSSbjCFEorYXqrgDIP2FA",
    "shortSlugOption": "some value",
    "mediaFileAssetLink": "file Linl"
  },
  "1aBOO8tu3lUsjtICuIbUM5": {
    "title": "1aBOO8tu3lUsjtICuIbUM5",
    "uid": "1aBOO8tu3lUsjtICuIbUM5",
    "url": "/Author/1aBOO8tu3lUsjtICuIbUM5",
    "short": "details of shorts",
    "shortSlugOption": "options",
    "booleanField": "true"
  }
}

so to get entries from the Data object I have created map function to get the value and to fetch the DataDetails object I used Object.entries

for (const [key, value] of Object.entries(value.DataDetails)) {
  console.log(`${key}: ${value}`);
}

so I made some changes in my code to get the desire output the problem is I am getting this

let data=
[
  {
    system: {
      id: '4gSSbjCFEorYXqrgDIP2FA',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      shortSlugOption: {
        "en-us":`some value`
      },
      mediaFileAssetLink: {
        "za-op":`file Linl`
      },
      mediaFileAssetGalary: {
        "hi":`file link 2`
      },
      singleMediaImage: {
        "li-sd-op":`file link single`
      },
    }
  },
  {
    system: {
      id: '1aBOO8tu3lUsjtICuIbUM5',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      short: {
        "en-us":`details of shorts`
      },
      shortSlugOption: {
        "hi-In":`options`
      },
      booleanField: {
        "kl":`true`
      }
    }
  }
];

data.map((value)=>{
  var name = value.system.id;
  var details={};

for (const [key, values] of Object.entries(value.DataDetails)) {

 details[name]={
    title:value.system.id,
    uid:value.system.id,
    url:`/${value.system.name}/${value.system.id}`,
    key:`${values}`
  }

}
  console.log(details)
})

I was trying to add ${key} but it's not making me to do so I can't get the DataDetails value as key in my object

is there any possible way I can DataDetails value which are shortSlugOption, mediaFileAssetLink by removing en-us,za-op n all

as my expected value is because the name field are common in this  JSON object so I want to store common name field in One JSON file

{
  "4gSSbjCFEorYXqrgDIP2FA": {
    "title": "4gSSbjCFEorYXqrgDIP2FA",
    "uid": "4gSSbjCFEorYXqrgDIP2FA",
    "url": "/Author/4gSSbjCFEorYXqrgDIP2FA",
    "shortSlugOption": "some value",
    "mediaFileAssetLink": "file Linl"
  },
  "1aBOO8tu3lUsjtICuIbUM5": {
    "title": "1aBOO8tu3lUsjtICuIbUM5",
    "uid": "1aBOO8tu3lUsjtICuIbUM5",
    "url": "/Author/1aBOO8tu3lUsjtICuIbUM5",
    "short": "details of shorts",
    "shortSlugOption": "options",
    "booleanField": "true"
  }
}

Body:
Is this what you were looking for. Created the details Object separately and spreaded it in the next step. I took the first and only element coming from the Object.values array

let data=
[
  {
    system: {
      id: '4gSSbjCFEorYXqrgDIP2FA',
      type: 'Entry',
      name: `Author`
    },
    DataDetails: {
      shortSlugOption: {
        "en-us":`some value`
      },
      mediaFileAssetLink: {
        "za-op":`file Linl`
      },
      mediaFileAssetGalary: {
        "hi":`file link 2`
      },
      singleMediaImage: {
        "li-sd-op":`file link single`
      },
    }
  }
];

data.map((value)=>{
  var name = value.system.id;
  var details={};

for (const [key, values] of Object.entries(value.DataDetails)) {

let detailsObj = {}
Object.keys(value.DataDetails).forEach((detail) => {
    detailsObj[detail] = Object.values(value.DataDetails[detail])[0]
})

 details[name]={
    title:value.system.id,
    uid:value.system.id,
    url:`/${value.system.name}/${value.system.id}`,
        ...detailsObj
  }

}
  console.log(details)
})

To group by the name can use Array.reduce

let data = [{"system":{"id":"4gSSbjCFEorYXqrgDIP2FA","type":"Entry","name":"Author"},"DataDetails":{"shortSlugOption":{"en-us":"some value"},"mediaFileAssetLink":{"za-op":"file Linl"},"mediaFileAssetGalary":{"hi":"file link 2"},"singleMediaImage":{"li-sd-op":"file link single"}}},{"system":{"id":"1aBOO8tu3lUsjtICuIbUM5","type":"Entry","name":"Author"},"DataDetails":{"short":{"en-us":"details of shorts"},"shortSlugOption":{"hi-In":"options"},"booleanField":{"kl":"true"}}},{"system":{"id":"2pOUGnI1oRD7nsrYs600HA","type":"Entry","name":"testing"},"DataDetails":{"testingNewValue":{"en-uk":"details value"}}},{"system":{"id":"66rzYr2BpWL1VTBHdLTdSW","type":"Entry","name":"new"},"DataDetails":{"oneReference":{"ru-re":"values 1"},"multiReference":{"uk-es":"values 2"}}},{"system":{"id":"cIb5mqEBRWDD6hrNmFmFE","type":"Entry","name":"new"},"DataDetails":{"testingNewValue":{"hi-IN":"jksdsdo"}}},{"system":{"id":"7kRzyt4PFrX13gHcw3Z1Ko","type":"Entry","name":"testing"},"DataDetails":{"testingNewValue":{"en-us":"kknksdo"}}},{"system":{"id":"2OspeCtNK0sh2cPiuU9jIz","type":"Entry","name":"dummy"},"DataDetails":{"short":{"gh-we":"dfvndkssa"},"shortSlugOption":{"jk-cv":"sdocjosmdc"},"mediaFileAssetLink":{"en-us":"jdsojocis"},"booleanField":{"cb-af":"true"}}},{"system":{"id":"2eAmIIuG4xkLvatkU3RUSy","type":"Entry","name":"dummy"},"DataDetails":{"dummy":{"en-us":"dshcifdvk"},"india":{"kh-vh-we":"sdci"}}},{"system":{"id":"7hbdS3MgfZ73TOtlu1WfXw","type":"Entry","name":"dummy"},"DataDetails":{"testingNewValue":{"ax-lo":"sdcoklsdc"},"locationField":{"sd-op":"sdcndkdc"}}}]

let res = data.reduce((acc,curr) => {
    if(!acc[curr.system.name]){
    acc[curr.system.name] = {}
  }

  let detailsObj = {}
Object.keys(curr.DataDetails).forEach((detail) => {
    detailsObj[detail] = Object.values(curr.DataDetails[detail])[0]
})

  acc[curr.system.name][curr.system.id] = {
    title:curr.system.id,
    uid:curr.system.id,
        url:`/${curr.system.name}/${curr.system.id}`,
    ...detailsObj
  }
  return acc;
},{})

console.log(res)

The result of a specific name can be accessed as res['Author'] for example


问:
Python ModuleNotFoundError when importing custom modules
I have the following project structure
Project Structure

In utils.py I am importing a parse function form parser.py file like this

from logica.parser.parser import parse

In builder.py I am importing a function from utils.py that uses the parser function like this

from utils.utils import utils

When trying to run all this stuff I get a ModuleNotFoundError:

ModuleNotFoundError: No module named 'logica'

Do you guys have any ideas on how to resolve the issue?

Thanks

答:
In Python you can only import modules installed via pip or files stored in the same directory of the current file.

To solve this problem you can do this:

```<code>import sys
sys.path.append(<path-of-the-module>)
</code>```

I would suggest to read also this.

Body:
In Python you can only import modules installed via pip or files stored in the same directory of the current file.

To solve this problem you can do this:

import sys
sys.path.append(<path-of-the-module>)

I would suggest to read also this.


问:
Why is my attempt to fit a tanh(x) function to data not working well?
I've got data of anode currents for different anode voltages. I'm trying to fit a tanh(x) curve to the resulting I-V curve using curve_fit, but I keep getting a line.

Since I'm trying to fit a curve to y against log10(x) I did the curve_fit 2 ways:

I took the log10 of the data first and fit the curve second

I fit the curve first and took the log10 of the data second.

Method 1 code and output:

```<code>import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def fitfunction(v, a, b, c, d):
    return a * np.tanh(b * v + c) + d

# x data = V90
# y data = np.log10(I90)

pars, cov = curve_fit(fitfunction, V90, np.log10(I90))

plt.plot(V90, fitfunction(V90, *pars), 'r-', linewidth='3', label='Line of Best Fit')
plt.scatter(V90, np.log10(I90), marker='.', label='Data')

plt.title('Graph of Line of Best Fit of Anode Current against Anode Potential')
plt.grid(True)
plt.xlabel('Voltage (V)')
plt.ylabel('Current (A)')
plt.legend()
plt.show()
</code>```

The resulting graph using the above code was:

Method 2 code and output:

```<code>pars, cov = curve_fit(fitfunction, V90, I90)
print(pars)

y = fitfunction(V90, *pars)

if any(i < 0 for i in y) == True:
    y = y + abs(min(y))

y = y[377:]
x = V90[377:]

plt.plot(x, np.log10(y), 'r-', linewidth='3', label='Line of Best Fit')
plt.scatter(V90, np.log10(I90), marker='.', label='Data')

plt.title('Graph of Line of Best Fit of Anode Current against Anode Potential')
plt.grid(True)
plt.xlabel('Voltage (V)')
plt.ylabel('Current (A)')
plt.legend()
plt.show()
</code>```

The resulting graph using this code was:

I'm not quite sure why in the second method, even if I do cut off the 0 values, there is still such a drastic deviation when V90 < 0.

The part of the data that's causing problems seems to be somewhere in 2.5V-5.0V which is about 500 lines of data:

```<code>#Voltages(V) Currents(A) Af=89.9mA Vf=24.3V
2.50000,0.0003815846315912
2.50500,0.0003816979315912
2.51000,0.0003817056315912
2.51500,0.00038173013159120006
2.52000,0.00038178253159120004
2.52500,0.0003818257315912
2.53000,0.0003819050315912
2.53500,0.0003818466315912
2.54000,0.0003818978315912
2.54500,0.0003819977315912
2.55000,0.00038197953159120005
2.55500,0.00038198843159120005
2.56000,0.00038210623159120005
2.56500,0.00038209303159120005
2.57000,0.0003821845315912
2.57500,0.0003821863315912
2.58000,0.00038220063159120004
2.58500,0.0003822367315912
2.59000,0.00038230733159120005
2.59500,0.00038230853159120003
2.60000,0.00038232433159120005
2.60500,0.0003823070315912
2.61000,0.0003824262315912
2.61500,0.0003824784315912
2.62000,0.0003825377315912
2.62500,0.0003825299315912
2.63000,0.0003825463315912
2.63500,0.00038256423159120005
2.64000,0.00038260893159120006
2.64500,0.0003826748315912
2.65000,0.0003826939315912
2.65500,0.0003826620315912
2.66000,0.00038270823159120004
2.66500,0.00038275413159120003
2.67000,0.0003827898315912
2.67500,0.0003828730315912
2.68000,0.00038286673159120005
2.68500,0.00038290933159120004
2.69000,0.0003829376315912
2.69500,0.0003829943315912
2.70000,0.0003830041315912
2.70500,0.00038304703159120005
2.71000,0.0003830539315912
2.71500,0.0003830631315912
2.72000,0.0003831442315912
2.72500,0.00038314893159120005
2.73000,0.0003831841315912
2.73500,0.0003832354315912
2.74000,0.00038327293159120005
2.74500,0.0003833084315912
2.75000,0.0003833653315912
2.75500,0.0003834109315912
2.76000,0.00038340913159120004
2.76500,0.0003834842315912
2.77000,0.00038352123159120005
2.77500,0.00038353283159120005
2.78000,0.00038357873159120003
2.78500,0.00038351133159120004
2.79000,0.00038353613159120004
2.79500,0.0003836058315912
2.80000,0.00038369733159120004
2.80500,0.0003836595315912
2.81000,0.00038369343159120006
2.81500,0.0003837056315912
2.82000,0.0003837095315912
2.82500,0.0003837635315912
2.83000,0.0003838389315912
2.83500,0.00038387283159120004
2.84000,0.00038388863159120006
2.84500,0.00038390353159120004
2.85000,0.00038393663159120005
2.85500,0.00038400643159120006
2.86000,0.00038402783159120004
2.86500,0.0003840540315912
2.87000,0.00038411223159120003
2.87500,0.00038411843159120003
2.88000,0.0003841074315912
2.88500,0.0003841589315912
2.89000,0.00038417953159120005
2.89500,0.0003841864315912
2.90000,0.00038419383159120005
2.90500,0.0003842904315912
2.91000,0.0003843029315912
2.91500,0.0003842731315912
2.92000,0.0003843509315912
2.92500,0.0003843986315912
2.93000,0.00038439503159120003
2.93500,0.0003843986315912
2.94000,0.00038445253159120007
2.94500,0.0003844441315912
2.95000,0.00038448443159120005
2.95500,0.00038446503159120005
2.96000,0.00038451213159120006
2.96500,0.0003845723315912
2.97000,0.0003846322315912
2.97500,0.0003846078315912
2.98000,0.00038468173159120005
2.98500,0.0003846975315912
2.99000,0.00038470823159120004
2.99500,0.00038466083159120003
3.00000,0.00038470853159120003
3.00500,0.00038475533159120005
3.01000,0.00038481043159120003
3.01500,0.0003848238315912
3.02000,0.0003848566315912
3.02500,0.00038489833159120003
3.03000,0.0003848757315912
3.03500,0.0003849278315912
3.04000,0.0003849609315912
3.04500,0.0003849475315912
3.05000,0.0003850175315912
3.05500,0.0003850137315912
3.06000,0.0003850512315912
3.06500,0.0003851350315912
3.07000,0.0003850923315912
3.07500,0.0003851168315912
3.08000,0.00038514873159120003
3.08500,0.0003851388315912
3.09000,0.00038523033159120005
3.09500,0.00038527003159120004
3.10000,0.00038524373159120007
3.10500,0.00038534923159120005
3.11000,0.0003853215315912
3.11500,0.00038534393159120003
3.12000,0.0003853278315912
3.12500,0.0003853394315912
3.13000,0.0003853603315912
3.13500,0.0003853787315912
3.14000,0.00038547143159120003
3.14500,0.0003854083315912
3.15000,0.00038548693159120006
3.15500,0.00038548843159120003
3.16000,0.00038548723159120005
3.16500,0.0003855608315912
3.17000,0.0003855918315912
3.17500,0.0003855635315912
3.18000,0.0003856055315912
3.18500,0.00038563923159120006
3.19000,0.0003856708315912
3.19500,0.00038566013159120003
3.20000,0.0003857125315912
3.20500,0.00038573913159120003
3.21000,0.00038580913159120005
3.21500,0.00038580463159120003
3.22000,0.0003858180315912
3.22500,0.0003858449315912
3.23000,0.00038583533159120004
3.23500,0.00038587913159120006
3.24000,0.0003858967315912
3.24500,0.0003858645315912
3.25000,0.0003859590315912
3.25500,0.0003859778315912
3.26000,0.00038596353159120006
3.26500,0.00038597303159120005
3.27000,0.00038599453159120006
3.27500,0.0003860436315912
3.28000,0.0003860785315912
3.28500,0.0003860782315912
3.29000,0.00038609913159120006
3.29500,0.0003861384315912
3.30000,0.0003861640315912
3.30500,0.0003861927315912
3.31000,0.0003862037315912
3.31500,0.0003861900315912
3.32000,0.0003862180315912
3.32500,0.00038625343159120004
3.33000,0.00038624963159120004
3.33500,0.0003862892315912
3.34000,0.0003863312315912
3.34500,0.00038631103159120006
3.35000,0.00038635183159120004
3.35500,0.00038638793159120004
3.36000,0.0003863819315912
3.36500,0.0003864013315912
3.37000,0.00038648713159120004
3.37500,0.0003864919315912
3.38000,0.00038650973159120005
3.38500,0.0003865127315912
3.39000,0.0003865819315912
3.39500,0.0003865768315912
3.40000,0.00038658543159120006
3.40500,0.00038663733159120003
3.41000,0.00038662423159120006
3.41500,0.0003866617315912
3.42000,0.00038666563159120003
3.42500,0.0003866883315912
3.43000,0.00038664123159120006
3.43500,0.00038672403159120005
3.44000,0.0003867511315912
3.44500,0.00038671243159120005
3.45000,0.00038679173159120005
3.45500,0.00038677233159120004
3.46000,0.0003867619315912
3.46500,0.0003867944315912
3.47000,0.00038678993159120003
3.47500,0.0003868668315912
3.48000,0.00038685753159120004
3.48500,0.0003868131315912
3.49000,0.0003868772315912
3.49500,0.00038690763159120005
3.50000,0.00038699083159120007
3.50500,0.0003869496315912
3.51000,0.0003869472315912
3.51500,0.0003870432315912
3.52000,0.0003870340315912
3.52500,0.0003870396315912
3.53000,0.0003870617315912
3.53500,0.0003870569315912
3.54000,0.00038713173159120003
3.54500,0.00038711033159120005
3.55000,0.00038715503159120006
3.55500,0.00038715383159120003
3.56000,0.0003871439315912
3.56500,0.00038713713159120003
3.57000,0.00038718153159120005
3.57500,0.00038722833159120007
3.58000,0.0003871866315912
3.58500,0.0003872426315912
3.59000,0.0003872560315912
3.59500,0.00038726643159120005
3.60000,0.0003872912315912
3.60500,0.0003872947315912
3.61000,0.0003873543315912
3.61500,0.00038739643159120004
3.62000,0.0003873946315912
3.62500,0.0003874357315912
3.63000,0.00038740023159120003
3.63500,0.0003874494315912
3.64000,0.00038744203159120003
3.64500,0.00038750963159120004
3.65000,0.00038753823159120004
3.65500,0.0003876038315912
3.66000,0.0003876062315912
3.66500,0.0003876419315912
3.67000,0.00038765513159120006
3.67500,0.00038764313159120003
3.68000,0.0003876282315912
3.68500,0.0003876902315912
3.69000,0.0003876959315912
3.69500,0.0003877227315912
3.70000,0.0003877594315912
3.70500,0.0003877594315912
3.71000,0.00038777433159120005
3.71500,0.0003877194315912
3.72000,0.0003878219315912
3.72500,0.00038785143159120005
3.73000,0.0003878336315912
3.73500,0.00038787443159120003
3.74000,0.0003878839315912
3.74500,0.00038790993159120004
3.75000,0.0003879575315912
3.75500,0.0003880106315912
3.76000,0.00038798413159120003
3.76500,0.0003880049315912
3.77000,0.0003880705315912
3.77500,0.00038805773159120003
3.78000,0.0003880672315912
3.78500,0.00038812413159120007
3.79000,0.0003881292315912
3.79500,0.00038814233159120004
3.80000,0.0003881444315912
3.80500,0.0003881864315912
3.81000,0.0003881593315912
3.81500,0.0003881632315912
3.82000,0.0003881823315912
3.82500,0.00038825473159120004
3.83000,0.0003882901315912
3.83500,0.00038829763159120003
3.84000,0.0003882907315912
3.84500,0.00038834053159119997
3.85000,0.0003883670315912
3.85500,0.0003883939315912
3.86000,0.0003883834315912
3.86500,0.0003883804315912
3.87000,0.0003884391315912
3.87500,0.0003884344315912
3.88000,0.0003884836315912
3.88500,0.00038849013159120003
3.89000,0.00038856043159120004
3.89500,0.0003885616315912
3.90000,0.00038857123159120004
3.90500,0.0003886108315912
3.91000,0.0003886305315912
3.91500,0.0003886633315912
3.92000,0.00038866483159119997
3.92500,0.0003886671315912
3.93000,0.00038875213159120003
3.93500,0.0003887288315912
3.94000,0.0003887735315912
3.94500,0.0003887700315912
3.95000,0.00038872023159120005
3.95500,0.00038880303159120004
3.96000,0.0003888695315912
3.96500,0.0003888597315912
3.97000,0.00038894643159120005
3.97500,0.0003889258315912
3.98000,0.00038898183159120003
3.98500,0.0003889664315912
3.99000,0.0003889261315912
3.99500,0.00038897353159120007
4.00000,0.0003890727315912
4.00500,0.0003890072315912
4.01000,0.00038906323159120003
4.01500,0.00038904213159120005
4.02000,0.00038912523159120003
4.02500,0.0003891359315912
4.03000,0.0003891619315912
4.03500,0.0003891288315912
4.04000,0.0003892173315912
4.04500,0.0003891940315912
4.05000,0.0003892384315912
4.05500,0.0003893127315912
4.06000,0.0003893159315912
4.06500,0.0003892709315912
4.07000,0.0003892769315912
4.07500,0.0003892754315912
4.08000,0.00038935383159120003
4.08500,0.00038933983159120003
4.09000,0.00038941553159120004
4.09500,0.00038942323159120006
4.10000,0.0003894319315912
4.10500,0.0003895219315912
4.11000,0.0003895454315912
4.11500,0.00038950883159120003
4.12000,0.0003896175315912
4.12500,0.00038962773159120003
4.13000,0.0003896372315912
4.13500,0.0003896017315912
4.14000,0.0003896599315912
4.14500,0.00038967243159120004
4.15000,0.00038972243159120007
4.15500,0.00038967923159120003
4.16000,0.0003897564315912
4.16500,0.00038985093159120003
4.17000,0.0003898157315912
4.17500,0.0003898777315912
4.18000,0.00038985683159120004
4.18500,0.00038996063159120003
4.19000,0.00038990393159120005
4.19500,0.0003898995315912
4.20000,0.00039002143159120006
4.20500,0.0003900357315912
4.21000,0.00039002343159120004
4.21500,0.00039006813159120005
4.22000,0.00039010213159120004
4.22500,0.0003901114315912
4.23000,0.0003901018315912
4.23500,0.0003901289315912
4.24000,0.0003902195315912
4.24500,0.0003902076315912
4.25000,0.00039021833159120004
4.25500,0.0003902306315912
4.26000,0.00039023533159120003
4.26500,0.00039031403159120004
4.27000,0.0003903662315912
4.27500,0.00039037843159120004
4.28000,0.00039042283159120006
4.28500,0.0003903867315912
4.29000,0.00039044223159120006
4.29500,0.0003904630315912
4.30000,0.0003904529315912
4.30500,0.0003904729315912
4.31000,0.00039054473159120005
4.31500,0.0003905533315912
4.32000,0.0003905974315912
4.32500,0.0003905998315912
4.33000,0.0003906898315912
4.33500,0.00039066933159120004
4.34000,0.00039072833159120004
4.34500,0.00039076823159120004
4.35000,0.0003907929315912
4.35500,0.00039083443159120007
4.36000,0.0003908636315912
4.36500,0.00039086923159120006
4.37000,0.00039087253159120005
4.37500,0.0003908964315912
4.38000,0.0003909136315912
4.38500,0.00039098463159120006
4.39000,0.0003910287315912
4.39500,0.0003910355315912
4.40000,0.0003910477315912
4.40500,0.0003910922315912
4.41000,0.0003910749315912
4.41500,0.0003911458315912
4.42000,0.0003911830315912
4.42500,0.00039118783159120007
4.43000,0.00039116373159120004
4.43500,0.0003912555315912
4.44000,0.0003912483315912
4.44500,0.00039127843159120006
4.45000,0.0003914009315912
4.45500,0.0003913550315912
4.46000,0.00039139433159120007
4.46500,0.0003914075315912
4.47000,0.0003914602315912
4.47500,0.0003914307315912
4.48000,0.0003914930315912
4.48500,0.0003914924315912
4.49000,0.00039153143159120004
4.49500,0.00039155053159120004
4.50000,0.0003916068315912
4.50500,0.0003916372315912
4.51000,0.00039167213159120004
4.51500,0.00039174183159120006
4.52000,0.00039177053159120004
4.52500,0.00039176813159120003
4.53000,0.00039181583159120004
4.53500,0.0003918697315912
4.54000,0.00039187893159120003
4.54500,0.0003918822315912
4.55000,0.0003919370315912
4.55500,0.0003919138315912
4.56000,0.0003919716315912
4.56500,0.00039199283159120006
4.57000,0.00039201103159120003
4.57500,0.00039209833159120004
4.58000,0.00039208733159120003
4.58500,0.0003921516315912
4.59000,0.0003921233315912
4.59500,0.00039217223159120003
4.60000,0.0003922100315912
4.60500,0.0003922246315912
4.61000,0.0003922810315912
4.61500,0.00039230933159120006
4.62000,0.00039232663159120005
4.62500,0.0003923683315912
4.63000,0.00039239963159120006
4.63500,0.0003924449315912
4.64000,0.00039247533159120007
4.64500,0.0003924917315912
4.65000,0.0003925414315912
4.65500,0.0003925510315912
4.66000,0.0003926022315912
4.66500,0.00039258413159120003
4.67000,0.0003926276315912
4.67500,0.0003927253315912
4.68000,0.0003927191315912
4.68500,0.0003926767315912
4.69000,0.0003927778315912
4.69500,0.0003928117315912
4.70000,0.0003928255315912
4.70500,0.00039284933159120005
4.71000,0.00039287673159120007
4.71500,0.0003929137315912
4.72000,0.00039292833159120004
4.72500,0.00039297333159120005
4.73000,0.00039305613159120004
4.73500,0.00039298043159120003
4.74000,0.00039306123159120004
4.74500,0.00039308923159120005
4.75000,0.0003931020315912
4.75500,0.0003931107315912
4.76000,0.00039316343159120004
4.76500,0.00039320483159120006
4.77000,0.00039318313159120003
4.77500,0.0003932430315912
4.78000,0.00039328623159120006
4.78500,0.0003932948315912
4.79000,0.0003933348315912
4.79500,0.0003933708315912
4.80000,0.0003934275315912
4.80500,0.0003934933315912
4.81000,0.0003933869315912
4.81500,0.00039350763159120005
4.82000,0.00039353273159120004
4.82500,0.0003935321315912
4.83000,0.0003935798315912
4.83500,0.0003935836315912
4.84000,0.0003936641315912
4.84500,0.00039368763159120006
4.85000,0.00039365193159120003
4.85500,0.00039369873159120005
4.86000,0.0003937326315912
4.86500,0.00039382033159120005
4.87000,0.0003938480315912
4.87500,0.00039383903159120003
4.88000,0.0003938897315912
4.88500,0.0003940000315912
4.89000,0.0003939517315912
4.89500,0.0003940104315912
4.90000,0.0003940086315912
4.90500,0.0003939877315912
4.91000,0.00039403513159120006
4.91500,0.00039411413159120006
4.92000,0.0003941618315912
4.92500,0.00039414903159120003
4.93000,0.00039421843159120006
4.93500,0.00039421603159120006
4.94000,0.00039430313159120005
4.94500,0.0003943028315912
4.95000,0.0003943370315912
4.95500,0.0003943808315912
4.96000,0.0003943910315912
4.96500,0.00039442853159120004
4.97000,0.0003944494315912
4.97500,0.00039449833159120004
4.98000,0.00039456143159120004
4.98500,0.0003945686315912
4.99000,0.0003945677315912
4.99500,0.0003946011315912
</code>```

答:
Here is a bit of code, based on yours.  Here, there is an option to read from a file, or curve fit perfect data that is created on the fly. If you have "nice" values, like (a,b,c,d)=1,2,3,4, and take the log of the data, the curve fit does well.  However, if you fiddle with the parameters, you can wind up with bad fits, even with "perfect" data.  I did notice that when rejecting the data V<-3.0, and not taking the log10(I90), you get a fit that looks OK, but it isn't perfect. When trying data when V>-2.5, and taking the log of the I90 data, you get this, which isn't bad:

```<code>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
https://stackoverflow.com/questions/71008658/how-to-fit-a-tanhx-function-to-data-in-python?noredirect=1#71008658

test code to check tanh fitting

"""

import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np

def fitfunction(v,a,b,c,d):
    return (a * np.tanh((b * v) + c) + d)

# x data = V90
# y data = np.log10(I90)

# read data from file
readdata=False

if(readdata==True):
    # arr = np.loadtxt("anode_90ma_test1.csv", delimiter=",")
    arr = np.loadtxt("test_data4.csv", delimiter=",")
    V90=arr[:,0]
    # option of using raw data or log of raw data
    I90=arr[:,1]
    # I90=np.log10(arr[:,1])

else:
    a_coeff=100
    b_coeff=1
    c_coeff=0.2
    d_coeff=-99
    V90=np.arange(-4,4,0.1)
    createvalues = np.vectorize(fitfunction)
    I90=createvalues(V90,a_coeff,b_coeff,c_coeff,d_coeff)
    # optionally take log10
    # I90=np.log10(I90)

# pars, cov = curve_fit(fitfunction,V90,np.log10(I90))
pars, cov = curve_fit(fitfunction,V90,I90)
print("fit pars = ",pars)

plt.plot(V90,fitfunction(V90,*pars),'r-',linewidth='3',label='Line of Best Fit')
plt.scatter(V90,I90,marker='.',label='Data')

plt.title('Graph of Line of Best Fit of Anode Current against Anode Potential')
plt.grid(True)
plt.xlabel('Voltage (V)')
plt.ylabel('Current (A)')
plt.legend()
plt.show()
</code>```

Body:
I've got data of anode currents for different anode voltages. I'm trying to fit a tanh(x) curve to the resulting I-V curve using curve_fit, but I keep getting a line.

Since I'm trying to fit a curve to y against log10(x) I did the curve_fit 2 ways:

I took the log10 of the data first and fit the curve second

I fit the curve first and took the log10 of the data second.

Method 1 code and output:

import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def fitfunction(v, a, b, c, d):
    return a * np.tanh(b * v + c) + d

# x data = V90
# y data = np.log10(I90)

pars, cov = curve_fit(fitfunction, V90, np.log10(I90))

plt.plot(V90, fitfunction(V90, *pars), 'r-', linewidth='3', label='Line of Best Fit')
plt.scatter(V90, np.log10(I90), marker='.', label='Data')

plt.title('Graph of Line of Best Fit of Anode Current against Anode Potential')
plt.grid(True)
plt.xlabel('Voltage (V)')
plt.ylabel('Current (A)')
plt.legend()
plt.show()

The resulting graph using the above code was:

Method 2 code and output:

pars, cov = curve_fit(fitfunction, V90, I90)
print(pars)

y = fitfunction(V90, *pars)

if any(i < 0 for i in y) == True:
    y = y + abs(min(y))

y = y[377:]
x = V90[377:]

plt.plot(x, np.log10(y), 'r-', linewidth='3', label='Line of Best Fit')
plt.scatter(V90, np.log10(I90), marker='.', label='Data')

plt.title('Graph of Line of Best Fit of Anode Current against Anode Potential')
plt.grid(True)
plt.xlabel('Voltage (V)')
plt.ylabel('Current (A)')
plt.legend()
plt.show()

The resulting graph using this code was:

I'm not quite sure why in the second method, even if I do cut off the 0 values, there is still such a drastic deviation when V90 < 0.

The part of the data that's causing problems seems to be somewhere in 2.5V-5.0V which is about 500 lines of data:

#Voltages(V) Currents(A) Af=89.9mA Vf=24.3V
2.50000,0.0003815846315912
2.50500,0.0003816979315912
2.51000,0.0003817056315912
2.51500,0.00038173013159120006
2.52000,0.00038178253159120004
2.52500,0.0003818257315912
2.53000,0.0003819050315912
2.53500,0.0003818466315912
2.54000,0.0003818978315912
2.54500,0.0003819977315912
2.55000,0.00038197953159120005
2.55500,0.00038198843159120005
2.56000,0.00038210623159120005
2.56500,0.00038209303159120005
2.57000,0.0003821845315912
2.57500,0.0003821863315912
2.58000,0.00038220063159120004
2.58500,0.0003822367315912
2.59000,0.00038230733159120005
2.59500,0.00038230853159120003
2.60000,0.00038232433159120005
2.60500,0.0003823070315912
2.61000,0.0003824262315912
2.61500,0.0003824784315912
2.62000,0.0003825377315912
2.62500,0.0003825299315912
2.63000,0.0003825463315912
2.63500,0.00038256423159120005
2.64000,0.00038260893159120006
2.64500,0.0003826748315912
2.65000,0.0003826939315912
2.65500,0.0003826620315912
2.66000,0.00038270823159120004
2.66500,0.00038275413159120003
2.67000,0.0003827898315912
2.67500,0.0003828730315912
2.68000,0.00038286673159120005
2.68500,0.00038290933159120004
2.69000,0.0003829376315912
2.69500,0.0003829943315912
2.70000,0.0003830041315912
2.70500,0.00038304703159120005
2.71000,0.0003830539315912
2.71500,0.0003830631315912
2.72000,0.0003831442315912
2.72500,0.00038314893159120005
2.73000,0.0003831841315912
2.73500,0.0003832354315912
2.74000,0.00038327293159120005
2.74500,0.0003833084315912
2.75000,0.0003833653315912
2.75500,0.0003834109315912
2.76000,0.00038340913159120004
2.76500,0.0003834842315912
2.77000,0.00038352123159120005
2.77500,0.00038353283159120005
2.78000,0.00038357873159120003
2.78500,0.00038351133159120004
2.79000,0.00038353613159120004
2.79500,0.0003836058315912
2.80000,0.00038369733159120004
2.80500,0.0003836595315912
2.81000,0.00038369343159120006
2.81500,0.0003837056315912
2.82000,0.0003837095315912
2.82500,0.0003837635315912
2.83000,0.0003838389315912
2.83500,0.00038387283159120004
2.84000,0.00038388863159120006
2.84500,0.00038390353159120004
2.85000,0.00038393663159120005
2.85500,0.00038400643159120006
2.86000,0.00038402783159120004
2.86500,0.0003840540315912
2.87000,0.00038411223159120003
2.87500,0.00038411843159120003
2.88000,0.0003841074315912
2.88500,0.0003841589315912
2.89000,0.00038417953159120005
2.89500,0.0003841864315912
2.90000,0.00038419383159120005
2.90500,0.0003842904315912
2.91000,0.0003843029315912
2.91500,0.0003842731315912
2.92000,0.0003843509315912
2.92500,0.0003843986315912
2.93000,0.00038439503159120003
2.93500,0.0003843986315912
2.94000,0.00038445253159120007
2.94500,0.0003844441315912
2.95000,0.00038448443159120005
2.95500,0.00038446503159120005
2.96000,0.00038451213159120006
2.96500,0.0003845723315912
2.97000,0.0003846322315912
2.97500,0.0003846078315912
2.98000,0.00038468173159120005
2.98500,0.0003846975315912
2.99000,0.00038470823159120004
2.99500,0.00038466083159120003
3.00000,0.00038470853159120003
3.00500,0.00038475533159120005
3.01000,0.00038481043159120003
3.01500,0.0003848238315912
3.02000,0.0003848566315912
3.02500,0.00038489833159120003
3.03000,0.0003848757315912
3.03500,0.0003849278315912
3.04000,0.0003849609315912
3.04500,0.0003849475315912
3.05000,0.0003850175315912
3.05500,0.0003850137315912
3.06000,0.0003850512315912
3.06500,0.0003851350315912
3.07000,0.0003850923315912
3.07500,0.0003851168315912
3.08000,0.00038514873159120003
3.08500,0.0003851388315912
3.09000,0.00038523033159120005
3.09500,0.00038527003159120004
3.10000,0.00038524373159120007
3.10500,0.00038534923159120005
3.11000,0.0003853215315912
3.11500,0.00038534393159120003
3.12000,0.0003853278315912
3.12500,0.0003853394315912
3.13000,0.0003853603315912
3.13500,0.0003853787315912
3.14000,0.00038547143159120003
3.14500,0.0003854083315912
3.15000,0.00038548693159120006
3.15500,0.00038548843159120003
3.16000,0.00038548723159120005
3.16500,0.0003855608315912
3.17000,0.0003855918315912
3.17500,0.0003855635315912
3.18000,0.0003856055315912
3.18500,0.00038563923159120006
3.19000,0.0003856708315912
3.19500,0.00038566013159120003
3.20000,0.0003857125315912
3.20500,0.00038573913159120003
3.21000,0.00038580913159120005
3.21500,0.00038580463159120003
3.22000,0.0003858180315912
3.22500,0.0003858449315912
3.23000,0.00038583533159120004
3.23500,0.00038587913159120006
3.24000,0.0003858967315912
3.24500,0.0003858645315912
3.25000,0.0003859590315912
3.25500,0.0003859778315912
3.26000,0.00038596353159120006
3.26500,0.00038597303159120005
3.27000,0.00038599453159120006
3.27500,0.0003860436315912
3.28000,0.0003860785315912
3.28500,0.0003860782315912
3.29000,0.00038609913159120006
3.29500,0.0003861384315912
3.30000,0.0003861640315912
3.30500,0.0003861927315912
3.31000,0.0003862037315912
3.31500,0.0003861900315912
3.32000,0.0003862180315912
3.32500,0.00038625343159120004
3.33000,0.00038624963159120004
3.33500,0.0003862892315912
3.34000,0.0003863312315912
3.34500,0.00038631103159120006
3.35000,0.00038635183159120004
3.35500,0.00038638793159120004
3.36000,0.0003863819315912
3.36500,0.0003864013315912
3.37000,0.00038648713159120004
3.37500,0.0003864919315912
3.38000,0.00038650973159120005
3.38500,0.0003865127315912
3.39000,0.0003865819315912
3.39500,0.0003865768315912
3.40000,0.00038658543159120006
3.40500,0.00038663733159120003
3.41000,0.00038662423159120006
3.41500,0.0003866617315912
3.42000,0.00038666563159120003
3.42500,0.0003866883315912
3.43000,0.00038664123159120006
3.43500,0.00038672403159120005
3.44000,0.0003867511315912
3.44500,0.00038671243159120005
3.45000,0.00038679173159120005
3.45500,0.00038677233159120004
3.46000,0.0003867619315912
3.46500,0.0003867944315912
3.47000,0.00038678993159120003
3.47500,0.0003868668315912
3.48000,0.00038685753159120004
3.48500,0.0003868131315912
3.49000,0.0003868772315912
3.49500,0.00038690763159120005
3.50000,0.00038699083159120007
3.50500,0.0003869496315912
3.51000,0.0003869472315912
3.51500,0.0003870432315912
3.52000,0.0003870340315912
3.52500,0.0003870396315912
3.53000,0.0003870617315912
3.53500,0.0003870569315912
3.54000,0.00038713173159120003
3.54500,0.00038711033159120005
3.55000,0.00038715503159120006
3.55500,0.00038715383159120003
3.56000,0.0003871439315912
3.56500,0.00038713713159120003
3.57000,0.00038718153159120005
3.57500,0.00038722833159120007
3.58000,0.0003871866315912
3.58500,0.0003872426315912
3.59000,0.0003872560315912
3.59500,0.00038726643159120005
3.60000,0.0003872912315912
3.60500,0.0003872947315912
3.61000,0.0003873543315912
3.61500,0.00038739643159120004
3.62000,0.0003873946315912
3.62500,0.0003874357315912
3.63000,0.00038740023159120003
3.63500,0.0003874494315912
3.64000,0.00038744203159120003
3.64500,0.00038750963159120004
3.65000,0.00038753823159120004
3.65500,0.0003876038315912
3.66000,0.0003876062315912
3.66500,0.0003876419315912
3.67000,0.00038765513159120006
3.67500,0.00038764313159120003
3.68000,0.0003876282315912
3.68500,0.0003876902315912
3.69000,0.0003876959315912
3.69500,0.0003877227315912
3.70000,0.0003877594315912
3.70500,0.0003877594315912
3.71000,0.00038777433159120005
3.71500,0.0003877194315912
3.72000,0.0003878219315912
3.72500,0.00038785143159120005
3.73000,0.0003878336315912
3.73500,0.00038787443159120003
3.74000,0.0003878839315912
3.74500,0.00038790993159120004
3.75000,0.0003879575315912
3.75500,0.0003880106315912
3.76000,0.00038798413159120003
3.76500,0.0003880049315912
3.77000,0.0003880705315912
3.77500,0.00038805773159120003
3.78000,0.0003880672315912
3.78500,0.00038812413159120007
3.79000,0.0003881292315912
3.79500,0.00038814233159120004
3.80000,0.0003881444315912
3.80500,0.0003881864315912
3.81000,0.0003881593315912
3.81500,0.0003881632315912
3.82000,0.0003881823315912
3.82500,0.00038825473159120004
3.83000,0.0003882901315912
3.83500,0.00038829763159120003
3.84000,0.0003882907315912
3.84500,0.00038834053159119997
3.85000,0.0003883670315912
3.85500,0.0003883939315912
3.86000,0.0003883834315912
3.86500,0.0003883804315912
3.87000,0.0003884391315912
3.87500,0.0003884344315912
3.88000,0.0003884836315912
3.88500,0.00038849013159120003
3.89000,0.00038856043159120004
3.89500,0.0003885616315912
3.90000,0.00038857123159120004
3.90500,0.0003886108315912
3.91000,0.0003886305315912
3.91500,0.0003886633315912
3.92000,0.00038866483159119997
3.92500,0.0003886671315912
3.93000,0.00038875213159120003
3.93500,0.0003887288315912
3.94000,0.0003887735315912
3.94500,0.0003887700315912
3.95000,0.00038872023159120005
3.95500,0.00038880303159120004
3.96000,0.0003888695315912
3.96500,0.0003888597315912
3.97000,0.00038894643159120005
3.97500,0.0003889258315912
3.98000,0.00038898183159120003
3.98500,0.0003889664315912
3.99000,0.0003889261315912
3.99500,0.00038897353159120007
4.00000,0.0003890727315912
4.00500,0.0003890072315912
4.01000,0.00038906323159120003
4.01500,0.00038904213159120005
4.02000,0.00038912523159120003
4.02500,0.0003891359315912
4.03000,0.0003891619315912
4.03500,0.0003891288315912
4.04000,0.0003892173315912
4.04500,0.0003891940315912
4.05000,0.0003892384315912
4.05500,0.0003893127315912
4.06000,0.0003893159315912
4.06500,0.0003892709315912
4.07000,0.0003892769315912
4.07500,0.0003892754315912
4.08000,0.00038935383159120003
4.08500,0.00038933983159120003
4.09000,0.00038941553159120004
4.09500,0.00038942323159120006
4.10000,0.0003894319315912
4.10500,0.0003895219315912
4.11000,0.0003895454315912
4.11500,0.00038950883159120003
4.12000,0.0003896175315912
4.12500,0.00038962773159120003
4.13000,0.0003896372315912
4.13500,0.0003896017315912
4.14000,0.0003896599315912
4.14500,0.00038967243159120004
4.15000,0.00038972243159120007
4.15500,0.00038967923159120003
4.16000,0.0003897564315912
4.16500,0.00038985093159120003
4.17000,0.0003898157315912
4.17500,0.0003898777315912
4.18000,0.00038985683159120004
4.18500,0.00038996063159120003
4.19000,0.00038990393159120005
4.19500,0.0003898995315912
4.20000,0.00039002143159120006
4.20500,0.0003900357315912
4.21000,0.00039002343159120004
4.21500,0.00039006813159120005
4.22000,0.00039010213159120004
4.22500,0.0003901114315912
4.23000,0.0003901018315912
4.23500,0.0003901289315912
4.24000,0.0003902195315912
4.24500,0.0003902076315912
4.25000,0.00039021833159120004
4.25500,0.0003902306315912
4.26000,0.00039023533159120003
4.26500,0.00039031403159120004
4.27000,0.0003903662315912
4.27500,0.00039037843159120004
4.28000,0.00039042283159120006
4.28500,0.0003903867315912
4.29000,0.00039044223159120006
4.29500,0.0003904630315912
4.30000,0.0003904529315912
4.30500,0.0003904729315912
4.31000,0.00039054473159120005
4.31500,0.0003905533315912
4.32000,0.0003905974315912
4.32500,0.0003905998315912
4.33000,0.0003906898315912
4.33500,0.00039066933159120004
4.34000,0.00039072833159120004
4.34500,0.00039076823159120004
4.35000,0.0003907929315912
4.35500,0.00039083443159120007
4.36000,0.0003908636315912
4.36500,0.00039086923159120006
4.37000,0.00039087253159120005
4.37500,0.0003908964315912
4.38000,0.0003909136315912
4.38500,0.00039098463159120006
4.39000,0.0003910287315912
4.39500,0.0003910355315912
4.40000,0.0003910477315912
4.40500,0.0003910922315912
4.41000,0.0003910749315912
4.41500,0.0003911458315912
4.42000,0.0003911830315912
4.42500,0.00039118783159120007
4.43000,0.00039116373159120004
4.43500,0.0003912555315912
4.44000,0.0003912483315912
4.44500,0.00039127843159120006
4.45000,0.0003914009315912
4.45500,0.0003913550315912
4.46000,0.00039139433159120007
4.46500,0.0003914075315912
4.47000,0.0003914602315912
4.47500,0.0003914307315912
4.48000,0.0003914930315912
4.48500,0.0003914924315912
4.49000,0.00039153143159120004
4.49500,0.00039155053159120004
4.50000,0.0003916068315912
4.50500,0.0003916372315912
4.51000,0.00039167213159120004
4.51500,0.00039174183159120006
4.52000,0.00039177053159120004
4.52500,0.00039176813159120003
4.53000,0.00039181583159120004
4.53500,0.0003918697315912
4.54000,0.00039187893159120003
4.54500,0.0003918822315912
4.55000,0.0003919370315912
4.55500,0.0003919138315912
4.56000,0.0003919716315912
4.56500,0.00039199283159120006
4.57000,0.00039201103159120003
4.57500,0.00039209833159120004
4.58000,0.00039208733159120003
4.58500,0.0003921516315912
4.59000,0.0003921233315912
4.59500,0.00039217223159120003
4.60000,0.0003922100315912
4.60500,0.0003922246315912
4.61000,0.0003922810315912
4.61500,0.00039230933159120006
4.62000,0.00039232663159120005
4.62500,0.0003923683315912
4.63000,0.00039239963159120006
4.63500,0.0003924449315912
4.64000,0.00039247533159120007
4.64500,0.0003924917315912
4.65000,0.0003925414315912
4.65500,0.0003925510315912
4.66000,0.0003926022315912
4.66500,0.00039258413159120003
4.67000,0.0003926276315912
4.67500,0.0003927253315912
4.68000,0.0003927191315912
4.68500,0.0003926767315912
4.69000,0.0003927778315912
4.69500,0.0003928117315912
4.70000,0.0003928255315912
4.70500,0.00039284933159120005
4.71000,0.00039287673159120007
4.71500,0.0003929137315912
4.72000,0.00039292833159120004
4.72500,0.00039297333159120005
4.73000,0.00039305613159120004
4.73500,0.00039298043159120003
4.74000,0.00039306123159120004
4.74500,0.00039308923159120005
4.75000,0.0003931020315912
4.75500,0.0003931107315912
4.76000,0.00039316343159120004
4.76500,0.00039320483159120006
4.77000,0.00039318313159120003
4.77500,0.0003932430315912
4.78000,0.00039328623159120006
4.78500,0.0003932948315912
4.79000,0.0003933348315912
4.79500,0.0003933708315912
4.80000,0.0003934275315912
4.80500,0.0003934933315912
4.81000,0.0003933869315912
4.81500,0.00039350763159120005
4.82000,0.00039353273159120004
4.82500,0.0003935321315912
4.83000,0.0003935798315912
4.83500,0.0003935836315912
4.84000,0.0003936641315912
4.84500,0.00039368763159120006
4.85000,0.00039365193159120003
4.85500,0.00039369873159120005
4.86000,0.0003937326315912
4.86500,0.00039382033159120005
4.87000,0.0003938480315912
4.87500,0.00039383903159120003
4.88000,0.0003938897315912
4.88500,0.0003940000315912
4.89000,0.0003939517315912
4.89500,0.0003940104315912
4.90000,0.0003940086315912
4.90500,0.0003939877315912
4.91000,0.00039403513159120006
4.91500,0.00039411413159120006
4.92000,0.0003941618315912
4.92500,0.00039414903159120003
4.93000,0.00039421843159120006
4.93500,0.00039421603159120006
4.94000,0.00039430313159120005
4.94500,0.0003943028315912
4.95000,0.0003943370315912
4.95500,0.0003943808315912
4.96000,0.0003943910315912
4.96500,0.00039442853159120004
4.97000,0.0003944494315912
4.97500,0.00039449833159120004
4.98000,0.00039456143159120004
4.98500,0.0003945686315912
4.99000,0.0003945677315912
4.99500,0.0003946011315912

Body:
Here is a bit of code, based on yours.  Here, there is an option to read from a file, or curve fit perfect data that is created on the fly. If you have "nice" values, like (a,b,c,d)=1,2,3,4, and take the log of the data, the curve fit does well.  However, if you fiddle with the parameters, you can wind up with bad fits, even with "perfect" data.  I did notice that when rejecting the data V<-3.0, and not taking the log10(I90), you get a fit that looks OK, but it isn't perfect. When trying data when V>-2.5, and taking the log of the I90 data, you get this, which isn't bad:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
https://stackoverflow.com/questions/71008658/how-to-fit-a-tanhx-function-to-data-in-python?noredirect=1#71008658

test code to check tanh fitting

"""

import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np

def fitfunction(v,a,b,c,d):
    return (a * np.tanh((b * v) + c) + d)

# x data = V90
# y data = np.log10(I90)

# read data from file
readdata=False

if(readdata==True):
    # arr = np.loadtxt("anode_90ma_test1.csv", delimiter=",")
    arr = np.loadtxt("test_data4.csv", delimiter=",")
    V90=arr[:,0]
    # option of using raw data or log of raw data
    I90=arr[:,1]
    # I90=np.log10(arr[:,1])

else:
    a_coeff=100
    b_coeff=1
    c_coeff=0.2
    d_coeff=-99
    V90=np.arange(-4,4,0.1)
    createvalues = np.vectorize(fitfunction)
    I90=createvalues(V90,a_coeff,b_coeff,c_coeff,d_coeff)
    # optionally take log10
    # I90=np.log10(I90)

# pars, cov = curve_fit(fitfunction,V90,np.log10(I90))
pars, cov = curve_fit(fitfunction,V90,I90)
print("fit pars = ",pars)

plt.plot(V90,fitfunction(V90,*pars),'r-',linewidth='3',label='Line of Best Fit')
plt.scatter(V90,I90,marker='.',label='Data')

plt.title('Graph of Line of Best Fit of Anode Current against Anode Potential')
plt.grid(True)
plt.xlabel('Voltage (V)')
plt.ylabel('Current (A)')
plt.legend()
plt.show()


问:
Resolving imports in Rust
I'm having trouble with importing rand crate from crates.io. After adding the line rand="0.8.3" and then running command cargo build for the project, it keeps displaying the same errors:

error[E0432]: unresolved import `rand`
 --> main.rs:1:5
  |
1 | use rand::Rng;
  |     ^^^^ maybe a missing crate `rand`?

error[E0433]: failed to resolve: use of undeclared crate or module `rand`
 --> main.rs:4:25
  |
4 |     let secret_number = rand::thread_rng().gen_range(1..=11);
  |                         ^^^^ use of undeclared crate or module `rand`

error: aborting due to 2 previous errors
```
<p>the <strong>cargo.toml</strong> file</p>
```[package]
name = "roller"
version = "0.1.0"
authors = ["User"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.3"

```
<p>Basically the simplest reproducible example is this single line of code:</p>
``` use rand::Rng;

 fn main(){
    let secret_number = rand::thread_rng().gen_range(1..=11);
    print!("{}",secret_number);
 }
```
<p>What's wrong with it?</p>
<br>
Just in case:
<br>
The **cargo.lock**file:
```# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
 "cfg-if",
 "libc",
 "wasi",
]

[[package]]
name = "libc"
version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"

[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"

[[package]]
name = "rand"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
 "libc",
 "rand_chacha",
 "rand_core",
 "rand_hc",
]

[[package]]
name = "rand_chacha"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
 "ppv-lite86",
 "rand_core",
]

[[package]]
name = "rand_core"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
dependencies = [
 "getrandom",
]

[[package]]
name = "rand_hc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
 "rand_core",
]

[[package]]
name = "roller"
version = "0.1.0"
dependencies = [
 "rand",
]

[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
```

答:
In file Cargo.toml add lines:

```<code>[dependencies]
rand="0.3.14"
</code>```

And rebuild project!

It worked with these versions:

rustc 1.53.0

cargo 1.53.0

Took answer from here https://github.com/rust-lang/rust/issues/34616

Title: Resolving imports in Rust

Body:
I'm having trouble with importing rand crate from crates.io. After adding the line rand="0.8.3" and then running command cargo build for the project, it keeps displaying the same errors:

error[E0432]: unresolved import `rand`
 --> main.rs:1:5
  |
1 | use rand::Rng;
  |     ^^^^ maybe a missing crate `rand`?

error[E0433]: failed to resolve: use of undeclared crate or module `rand`
 --> main.rs:4:25
  |
4 |     let secret_number = rand::thread_rng().gen_range(1..=11);
  |                         ^^^^ use of undeclared crate or module `rand`

error: aborting due to 2 previous errors

the cargo.toml file

[package]
name = "roller"
version = "0.1.0"
authors = ["User"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.3"

Basically the simplest reproducible example is this single line of code:

 use rand::Rng;

 fn main(){
    let secret_number = rand::thread_rng().gen_range(1..=11);
    print!("{}",secret_number);
 }

What's wrong with it?

Just in case:

The **cargo.lock**file:

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
 "cfg-if",
 "libc",
 "wasi",
]

[[package]]
name = "libc"
version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"

[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"

[[package]]
name = "rand"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
 "libc",
 "rand_chacha",
 "rand_core",
 "rand_hc",
]

[[package]]
name = "rand_chacha"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
 "ppv-lite86",
 "rand_core",
]

[[package]]
name = "rand_core"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
dependencies = [
 "getrandom",
]

[[package]]
name = "rand_hc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
 "rand_core",
]

[[package]]
name = "roller"
version = "0.1.0"
dependencies = [
 "rand",
]

[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"

Body:
In file Cargo.toml add lines:

[dependencies]
rand="0.3.14"

And rebuild project!

It worked with these versions:

rustc 1.53.0

cargo 1.53.0

Took answer from here https://github.com/rust-lang/rust/issues/34616


问:
How can I get the impedance matrix of the network?
Is there any way to calculate impedance matrix of the network in pandapower?</p>

答:
Searching in  GitHub/Issues I came up with this:

Nodal Admittance Matrix:

```<code>Ybus = net._ppc["internal"]["Ybus"].todense()
</code>```

While the

Jacobian Matrix:

```<code>J = net._ppc["internal"]["J"].todense()
</code>```

Body:
Searching in  GitHub/Issues I came up with this:

Nodal Admittance Matrix:

Ybus = net._ppc["internal"]["Ybus"].todense()

While the

Jacobian Matrix:

J = net._ppc["internal"]["J"].todense()


问:
Convert Pandas DataFrame specific columns to dict(json format)
I have a Dataframe with four columns - key, value, min, max:

                   key       value  min   max
0              is_open        true    0     9
56              is_run       false    0     9
54          can_delete        true    0     9
53             content      Hello!    0     9
52        chat-profile     Discord    0     9

```
<p>I am trying to convert it to a dict(json format) with the following format - <code>{"key": "value", "key": "value", ... }</code>:</p>
<pre class="lang-py prettyprint-override"><code>{
    'is_open': 'true',
    'is_run': 'false',
    'can_delete': 'true',
    'content': 'Hello!',
    'chat-profile': 'Discord'
}

</code>```

So i wrote code like this.

result = {}
for _, row in df[['key', 'value']].iterrows():
    result[row['key']] = row['value']
```

However, this code seems to become slower as the number of rows increases.

Is there any faster and better way?

答:
You can do that with either of the following

```<code># 6.44 µs on 10 million rows
d = df.set_index('key')['value'].to_dict()

# 6.68 µs on 10 million rows
d = dict(zip(df['key'], df['value']))
</code>```

@Psidom's solution seems to be a little bit faster when testing on a dataframe with 10 million rows

Body:
I have a Dataframe with four columns - key, value, min, max:

                   key       value  min   max
0              is_open        true    0     9
56              is_run       false    0     9
54          can_delete        true    0     9
53             content      Hello!    0     9
52        chat-profile     Discord    0     9

I am trying to convert it to a dict(json format) with the following format - {"key": "value", "key": "value", ... }:

{
    'is_open': 'true',
    'is_run': 'false',
    'can_delete': 'true',
    'content': 'Hello!',
    'chat-profile': 'Discord'
}

So i wrote code like this.

result = {}
for _, row in df[['key', 'value']].iterrows():
    result[row['key']] = row['value']

However, this code seems to become slower as the number of rows increases.

Is there any faster and better way?

Body:
You can do that with either of the following

# 6.44 µs on 10 million rows
d = df.set_index('key')['value'].to_dict()

# 6.68 µs on 10 million rows
d = dict(zip(df['key'], df['value']))

@Psidom's solution seems to be a little bit faster when testing on a dataframe with 10 million rows


问:
Variable names with random numbers
I want to declare variables with random numbers in the name, such as

```<code>$var123 = "A"
$var456 = "B"
$var789 = "C"
</code>```

by using Get-Random for the number part.

What have I to write behind $var if $rnd = Get-Random? Or is there another way to declare such variables?

Update: The real use case is that I have trouble with Add-Type and hoped I could solve it with this workaround. But it still does not work as expected. It works for the very first time, but after changing the C# code, it still shows the old code.

Any suggestions? I am running PowerShell 7.2.1 on a Mac computer.

```<code>$rnd = Get-Random
$code =
@"
    using System;
    namespace HelloWorld {
        public class Program {
            public static int Main() {
                #return 123; # first try, working well
                return 456; # after changing, still returns 123
            }
        }
    }
"@

New-Variable -Name "var$rnd" -value $code
Add-Type -TypeDefinition (Get-Variable -Name "var$rnd" -ValueOnly) -Language CSharp
Write-Host (Invoke-Expression "[HelloWorld.Program]::Main()")
</code>```

答:
You would need to use New-Variable or Set-Variable if you want to dynamically create them with random names:

```<code>'A', 'B', 'C' | ForEach-Object {
    do {
        $varname = "var$(Get-Random -Minimum 100 -Maximum 1000)"
    } until($varname -notin (Get-Variable var*).Name)
    New-Variable -Name $varname -Value $_
}

Get-Variable var*
</code>```

Worth noting that, using above method will make an infinite loop if you create 901 variables with it. -Minimum and -Maximum should be tweaked if more variables are needed.

Regarding your update, I believe you already have been following this Q&A, one of the answers provides this workaround which is what I believe you wanted to do:

$rnd = Get-Random
$code = @"
using System;
namespace HelloWorld$rnd {
   public class Program {
       public static int Main() {
           return 123;
           // return 456;
       }
   }
}
"@

Add-Type -TypeDefinition $code -Language CSharp
Invoke-Expression "[HelloWorld$rnd.Program]::Main()"
```

Title: Variable names with random numbers

Body:
I want to declare variables with random numbers in the name, such as

$var123 = "A"
$var456 = "B"
$var789 = "C"

by using Get-Random for the number part.

What have I to write behind $var if $rnd = Get-Random? Or is there another way to declare such variables?

Update: The real use case is that I have trouble with Add-Type and hoped I could solve it with this workaround. But it still does not work as expected. It works for the very first time, but after changing the C# code, it still shows the old code.

Any suggestions? I am running PowerShell 7.2.1 on a Mac computer.

$rnd = Get-Random
$code =
@"
    using System;
    namespace HelloWorld {
        public class Program {
            public static int Main() {
                #return 123; # first try, working well
                return 456; # after changing, still returns 123
            }
        }
    }
"@

New-Variable -Name "var$rnd" -value $code
Add-Type -TypeDefinition (Get-Variable -Name "var$rnd" -ValueOnly) -Language CSharp
Write-Host (Invoke-Expression "[HelloWorld.Program]::Main()")

Body:
You would need to use New-Variable or Set-Variable if you want to dynamically create them with random names:

'A', 'B', 'C' | ForEach-Object {
    do {
        $varname = "var$(Get-Random -Minimum 100 -Maximum 1000)"
    } until($varname -notin (Get-Variable var*).Name)
    New-Variable -Name $varname -Value $_
}

Get-Variable var*

Worth noting that, using above method will make an infinite loop if you create 901 variables with it. -Minimum and -Maximum should be tweaked if more variables are needed.

Regarding your update, I believe you already have been following this Q&A, one of the answers provides this workaround which is what I believe you wanted to do:

$rnd = Get-Random
$code = @"
using System;
namespace HelloWorld$rnd {
   public class Program {
       public static int Main() {
           return 123;
           // return 456;
       }
   }
}
"@

Add-Type -TypeDefinition $code -Language CSharp
Invoke-Expression "[HelloWorld$rnd.Program]::Main()"


问:
Javascript to calculate pixel distance between top of div and top of document
As the title says, is there any function or simple method to calculate pixel distance between the top of a div and the top of the HTML document? All the questions I've seen on stackoverflow do it for top of div and top of viewport which is different than what I need. Thanks in advance.</p>

答:
Here is a function you could use, but I'm not sure it works on all contexts :

```<code>function topRelativeToDocumentElement(element) {
    var curCss, t=0;
    while (element!==null && element!==document.documentElement) {
        if ((defaultView=element.ownerDocument.defaultView) && (computedStyle=defaultView.getComputedStyle(element, null))) {
            curCss=computedStyle.getPropertyValue("position");
        } else {
            curCss=null;
        }
        if (curCss!=="static" && curCss!=="fixed") {
            t+=element.offsetTop;
        } else if (curCss==="fixed") {
            t+=element.offsetTop;
            break;
        }
        if (typeof(element.parentNode)!=="undefined") {
            element=element.parentNode;
        } else {
            break;
        }
    }
    return t;
}
</code>```

[Edit]
I would advise to use this instead :

```<code>var top=elem.getBoundingClientRect().top - document.documentElement.getBoundingClientRect().top
</code>```

The first function takes not in consideration css transforms, the second one does.

Body:
Here is a function you could use, but I'm not sure it works on all contexts :

function topRelativeToDocumentElement(element) {
    var curCss, t=0;
    while (element!==null && element!==document.documentElement) {
        if ((defaultView=element.ownerDocument.defaultView) && (computedStyle=defaultView.getComputedStyle(element, null))) {
            curCss=computedStyle.getPropertyValue("position");
        } else {
            curCss=null;
        }
        if (curCss!=="static" && curCss!=="fixed") {
            t+=element.offsetTop;
        } else if (curCss==="fixed") {
            t+=element.offsetTop;
            break;
        }
        if (typeof(element.parentNode)!=="undefined") {
            element=element.parentNode;
        } else {
            break;
        }
    }
    return t;
}

[Edit]
I would advise to use this instead :

var top=elem.getBoundingClientRect().top - document.documentElement.getBoundingClientRect().top

The first function takes not in consideration css transforms, the second one does.


问:
TableAdapter selected GridView Row and insert?
I am trying to get something of a selected GridView Row which is controlled with TableAdapter. (Visual Studio 2010, ASP.NET)

I have otobas.xsd. Inside that, I have Otobus and Sefer tables and also SeferTableAdapter and OtobusTableAdapter. I fill the gridview like this;

```<code>otobasTableAdapters.SeferTableAdapter sef = new otobasTableAdapters.SeferTableAdapter();
        otobas.SeferDataTable sefs;
        sefs = sef.GetData();

        SeferTableAdapter sefers = new SeferTableAdapter();
        GridView1.DataSource = sefers.GetData();
        GridView1.DataBind();
</code>```

On the GridView Table, I have Select buttons on each row, therefore, when the user clicks one of the select buttons, I want to know which row it was. And then, I want to get the row like this (however, I can't)

otobas.SeferRow rw = ...?

I don't know how to do that. I tried many things but I couldn't. After I get this rw, I want to do something like;

```<code>string id = rw['id'];
string arrival = rw['arrival'];
</code>```

However, I just couldn't do it. Can you show me a way to do this?  I tried to add a row but I also couldn't do it. I don't know how to create a row I think. I tried to do the same as

http://msdn.microsoft.com/en-US/library/5ycd1034%28v=VS.80%29.aspx

but, when I wrote

otobas.SeferRow newRow = otobas... I have a data table named Sefer, but I can't reference it at all. Is it wrong to make an instance of the otobas dataset? Like

```<code>otobas oto = new otobas();

otobas.SeferRow sr = oto.Sefer.... ?
</code>```

Why do I have to create an instance of otobas? I mean I already have it as otobas.xsd I just don't get it.

答: Haven't used this before but is it possible to implement an event handler for the onlclick event of this grid (in either client side or server side code) where you can make use of the event arguments to find this an other information you are searching for>?</p>

ContentLicense: CC BY-SA 3.0

Body:
I am trying to get something of a selected GridView Row which is controlled with TableAdapter. (Visual Studio 2010, ASP.NET)

I have otobas.xsd. Inside that, I have Otobus and Sefer tables and also SeferTableAdapter and OtobusTableAdapter. I fill the gridview like this;

otobasTableAdapters.SeferTableAdapter sef = new otobasTableAdapters.SeferTableAdapter();
        otobas.SeferDataTable sefs;
        sefs = sef.GetData();

        SeferTableAdapter sefers = new SeferTableAdapter();
        GridView1.DataSource = sefers.GetData();
        GridView1.DataBind();

On the GridView Table, I have Select buttons on each row, therefore, when the user clicks one of the select buttons, I want to know which row it was. And then, I want to get the row like this (however, I can't)

otobas.SeferRow rw = ...?

I don't know how to do that. I tried many things but I couldn't. After I get this rw, I want to do something like;

string id = rw['id'];
string arrival = rw['arrival'];

However, I just couldn't do it. Can you show me a way to do this?  I tried to add a row but I also couldn't do it. I don't know how to create a row I think. I tried to do the same as

http://msdn.microsoft.com/en-US/library/5ycd1034%28v=VS.80%29.aspx

but, when I wrote

otobas.SeferRow newRow = otobas... I have a data table named Sefer, but I can't reference it at all. Is it wrong to make an instance of the otobas dataset? Like

otobas oto = new otobas();

otobas.SeferRow sr = oto.Sefer.... ?

Why do I have to create an instance of otobas? I mean I already have it as otobas.xsd I just don't get it.


问:
How to control the space between flex items
I'm just doing some learning material on Codeacademy and I'm wanting to know how to control the space between the "locations" text and the three divs below. The assignment is asking me to create a 15px space between them but I don't know how to do that. Currently, there is just a default space that I don't know how is calculated.

html {
  text-align: center;
}

.location-container {
  background-image: url(https://content.codecademy.com/courses/freelance-1/unit-4/img-locations-background.jpg);
  height: 700px;
  width: 1200px;
  display: flex;
  justify-content: center;
  align-content: center;
  flex-wrap: wrap;
}

#local {
  background-color: blueviolet;
}

.location-columns {
  display: flex;
  justify-content: center;
  width: 100%;
  gap: 30px;
  color: white;
}

.locations {
  background-color: black;
  width: 300px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="location-container">

  <h2 id="local">Locations</h2>

  <div class="location-columns">
    <div class="locations">
      <h3>Downtown</h3>
      <h5>384 West 4th St</h5>
      <h5> Suite 108</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>East Baysuide</h3>
      <h5>3433 Phisermans Avenue</h5>
      <h5>(Northwest Corner)</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>Oakdale</h3>
      <h5>515 Crescent Avenue</h5>
      <h5> Second Floor</h5>
      <h5>Portland, Maine</h5>
    </div>
  </div></code>```

Thanks for any insights.

答:
Heading elements come with large upper and lower margins right from the default browser styles.

You can remove those for elements inside .locations, make it a flex container and use row-gap to control vertical spacing:

html {
  text-align: center;
}

.location-container {
  background-image: url(https://content.codecademy.com/courses/freelance-1/unit-4/img-locations-background.jpg);
  height: 700px;
  width: 1200px;
  display: flex;
  justify-content: center;
  align-content: center;
  flex-wrap: wrap;
}

#local {
  background-color: blueviolet;
}

.location-columns {
  display: flex;
  justify-content: center;
  width: 100%;
  gap: 30px;
  color: white;
}

.locations {
  background-color: black;
  display: flex;
  flex-direction: column;
  row-gap: 30px;
  padding: 30px;
  width: 300px;
}

.locations>* { margin: 0; }```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="location-container">

  <h2 id="local">Locations</h2>

  <div class="location-columns">
    <div class="locations">
      <h3>Downtown</h3>
      <h5>384 West 4th St</h5>
      <h5> Suite 108</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>East Baysuide</h3>
      <h5>3433 Phisermans Avenue</h5>
      <h5>(Northwest Corner)</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>Oakdale</h3>
      <h5>515 Crescent Avenue</h5>
      <h5> Second Floor</h5>
      <h5>Portland, Maine</h5>
    </div>
  </div></code>```

Body:
I'm just doing some learning material on Codeacademy and I'm wanting to know how to control the space between the "locations" text and the three divs below. The assignment is asking me to create a 15px space between them but I don't know how to do that. Currently, there is just a default space that I don't know how is calculated.

html {
  text-align: center;
}

.location-container {
  background-image: url(https://content.codecademy.com/courses/freelance-1/unit-4/img-locations-background.jpg);
  height: 700px;
  width: 1200px;
  display: flex;
  justify-content: center;
  align-content: center;
  flex-wrap: wrap;
}

#local {
  background-color: blueviolet;
}

.location-columns {
  display: flex;
  justify-content: center;
  width: 100%;
  gap: 30px;
  color: white;
}

.locations {
  background-color: black;
  width: 300px;
}

Locations

Downtown

384 West 4th St

 Suite 108

Portland, Maine

East Baysuide

3433 Phisermans Avenue

(Northwest Corner)

Portland, Maine

Oakdale

515 Crescent Avenue

 Second Floor

Portland, Maine

Thanks for any insights.

Body:
Heading elements come with large upper and lower margins right from the default browser styles.

You can remove those for elements inside .locations, make it a flex container and use row-gap to control vertical spacing:

html {
  text-align: center;
}

.location-container {
  background-image: url(https://content.codecademy.com/courses/freelance-1/unit-4/img-locations-background.jpg);
  height: 700px;
  width: 1200px;
  display: flex;
  justify-content: center;
  align-content: center;
  flex-wrap: wrap;
}

#local {
  background-color: blueviolet;
}

.location-columns {
  display: flex;
  justify-content: center;
  width: 100%;
  gap: 30px;
  color: white;
}

.locations {
  background-color: black;
  display: flex;
  flex-direction: column;
  row-gap: 30px;
  padding: 30px;
  width: 300px;
}

.locations>* { margin: 0; }

<div class="location-container">

  <h2 id="local">Locations</h2>

  <div class="location-columns">
    <div class="locations">
      <h3>Downtown</h3>
      <h5>384 West 4th St</h5>
      <h5> Suite 108</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>East Baysuide</h3>
      <h5>3433 Phisermans Avenue</h5>
      <h5>(Northwest Corner)</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>Oakdale</h3>
      <h5>515 Crescent Avenue</h5>
      <h5> Second Floor</h5>
      <h5>Portland, Maine</h5>
    </div>
  </div>


问:
Can you help me I want to print the value of factorial 4 but the following function is always giving NAN why?
My question is about recursive function why it is showing always NAN instead of showing the value of factorial 4.</p>
```<code>function factorial(i){
              if (i == 1) { return;}
              return i * factorial(--i);};
      console.log(factorial(4));
</code>```

答:
```<code>function factorial(i){
              if (i == 1) { return 1;}
              return i * factorial(--i);};
      console.log(factorial(4));
</code>```

That right.

Body:
My question is about recursive function why it is showing always NAN instead of showing the value of factorial 4.

function factorial(i){
              if (i == 1) { return;}
              return i * factorial(--i);};
      console.log(factorial(4));

Body:
function factorial(i){
              if (i == 1) { return 1;}
              return i * factorial(--i);};
      console.log(factorial(4));

That right.